CF1709A.Three Doors
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are three doors in front of you, numbered from 1 to 3 from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.
There are three keys — one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.
Can you open all the doors?
你面前有三扇门,从左到右依次编号为 1 到 3。每扇门上都有一把锁,只能用与门编号相同的钥匙才能打开。
共有三把钥匙——每扇门各对应一把。其中两把钥匙被藏在门后,且每扇门后至多藏有一把钥匙。因此,有两扇门后各藏有一把钥匙,一扇门后没有钥匙。若要取得藏在某扇门后的钥匙,你必须先打开那扇门。剩下的那一把钥匙在你手中。
你能否打开所有门?
输入格式
The first line contains a single integer t (1≤t≤18) — the number of testcases.
The first line of each testcase contains a single integer x (1≤x≤3) — the number on the key in your hands.
The second line contains three integers a,b and c (0≤a,b,c≤3) — the number on the key behind each of the doors. If there is no key behind the door, the number is equal to 0.
Values 1,2 and 3 appear exactly once among x,a,b and c.
第一行包含一个整数 t(1≤t≤18)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 x(1≤x≤3)—— 你手中钥匙上的数字。
每个测试用例的第二行包含三个整数 a,b 和 c(0≤a,b,c≤3)—— 每扇门后钥匙上的数字。若某扇门后没有钥匙,则对应数字为 0。
在 x,a,b 和 c 中,数字 1,2 和 3 恰好各出现一次。
输出格式
For each testcase, print "YES" if you can open all the doors. Otherwise, print "NO".
对于每个测试用例,如果可以打开所有门,则输出 "YES";否则,输出 "NO"。
输入输出样例
输入#1
4 3 0 1 2 1 0 3 2 2 3 1 0 2 1 3 0
输出#1
YES NO YES NO
输入解题思路,AI测评打分。不知道怎么写?