309626: CF1709A. Three Doors

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Three Doors

题意翻译

你面前有三扇门,从左到右从 $1$ 到 $3$ 号。每个门上都有一把锁,只有钥匙上的号码与门上的号码相同,才能打开。 有三把钥匙,每扇门一把。其中两扇门后面有一把钥匙,一扇门后面没有钥匙。剩下的那把钥匙在你手里。要获得在门后的钥匙,您应首先打开该门。 你能打开所有门吗? ### 输入格式: 第一行一个整数 $T$,表示有 $T$ 组数据。 对于每组数据,第一行一个整数 $x$,表示你手里钥匙的编号。 第二行包含三个整数 $a、b、c$,表示每个门后钥匙上的数字。如果门后没有钥匙,则数字是 $0$。 数字 $1、2、3$ 在 $a、b、c$ 中最多出现一次。 ### 输出格式: 对于每组数据,如果可以打开所有的门,请输出 `YES`。否则,输出 `NO`。

题目描述

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?

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \le t \le 18 $ ) — the number of testcases. The first line of each testcase contains a single integer $ x $ ( $ 1 \le x \le 3 $ ) — the number on the key in your hands. The second line contains three integers $ a, b $ and $ c $ ( $ 0 \le a, b, c \le 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 $ .

输出格式


For each testcase, print "YES" if you can open all the doors. Otherwise, print "NO".

输入输出样例

输入样例 #1

4
3
0 1 2
1
0 3 2
2
3 1 0
2
1 3 0

输出样例 #1

YES
NO
YES
NO

Input

题意翻译

你面前有三扇门,从左到右从 $1$ 到 $3$ 号。每个门上都有一把锁,只有钥匙上的号码与门上的号码相同,才能打开。 有三把钥匙,每扇门一把。其中两扇门后面有一把钥匙,一扇门后面没有钥匙。剩下的那把钥匙在你手里。要获得在门后的钥匙,您应首先打开该门。 你能打开所有门吗? ### 输入格式: 第一行一个整数 $T$,表示有 $T$ 组数据。 对于每组数据,第一行一个整数 $x$,表示你手里钥匙的编号。 第二行包含三个整数 $a、b、c$,表示每个门后钥匙上的数字。如果门后没有钥匙,则数字是 $0$。 数字 $1、2、3$ 在 $a、b、c$ 中最多出现一次。 ### 输出格式: 对于每组数据,如果可以打开所有的门,请输出 `YES`。否则,输出 `NO`。

Output

题目大意:你面前有三扇门,编号分别为1到3。每扇门都有一把锁,只能用相同编号的钥匙打开。共有三把钥匙,其中两把在门后,一把在你手中。你需要通过打开正确的门来获取门后的钥匙,并判断是否能够打开所有门。

输入数据格式:
- 第一行是一个整数T,表示有T组数据。
- 对于每组数据,第一行是一个整数x,表示你手中钥匙的编号。
- 第二行包含三个整数a、b、c,分别表示门1、门2、门3后钥匙的编号。如果门后没有钥匙,则编号为0。

输出数据格式:
- 对于每组数据,如果可以打开所有门,输出"YES"。否则,输出"NO"。

例如:

输入样例:
```
4
3
0 1 2
1
0 3 2
2
3 1 0
2
1 3 0
```

输出样例:
```
YES
NO
YES
NO
```题目大意:你面前有三扇门,编号分别为1到3。每扇门都有一把锁,只能用相同编号的钥匙打开。共有三把钥匙,其中两把在门后,一把在你手中。你需要通过打开正确的门来获取门后的钥匙,并判断是否能够打开所有门。 输入数据格式: - 第一行是一个整数T,表示有T组数据。 - 对于每组数据,第一行是一个整数x,表示你手中钥匙的编号。 - 第二行包含三个整数a、b、c,分别表示门1、门2、门3后钥匙的编号。如果门后没有钥匙,则编号为0。 输出数据格式: - 对于每组数据,如果可以打开所有门,输出"YES"。否则,输出"NO"。 例如: 输入样例: ``` 4 3 0 1 2 1 0 3 2 2 3 1 0 2 1 3 0 ``` 输出样例: ``` YES NO YES NO ```

加入题单

算法标签: