CF1598A.Computer Game
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Monocarp is playing a computer game. Now he wants to complete the first level of this game.
A level is a rectangular grid of 2 rows and n columns. Monocarp controls a character, which starts in cell (1,1) — at the intersection of the 1-st row and the 1-st column.
Monocarp's character can move from one cell to another in one step if the cells are adjacent by side and/or corner. Formally, it is possible to move from cell (x1,y1) to cell (x2,y2) in one step if ∣x1−x2∣≤1 and ∣y1−y2∣≤1. Obviously, it is prohibited to go outside the grid.
There are traps in some cells. If Monocarp's character finds himself in such a cell, he dies, and the game ends.
To complete a level, Monocarp's character should reach cell (2,n) — at the intersection of row 2 and column n.
Help Monocarp determine if it is possible to complete the level.
Monocarp 正在玩一款电脑游戏。现在他希望完成该游戏的第一关。
一关是一个 2 行 n 列的矩形网格。Monocarp 控制一个角色,该角色起始于单元格 (1,1) —— 即第 1 行与第 1 列的交点处。
Monocarp 的角色每步可从一个单元格移动到另一个单元格,当且仅当这两个单元格在边或角上相邻。形式化地说,从单元格 (x1,y1) 到单元格 (x2,y2) 的一步移动是允许的,当且仅当 ∣x1−x2∣≤1 且 ∣y1−y2∣≤1。显然,禁止移出网格边界。
某些单元格中设有陷阱。若 Monocarp 的角色进入此类单元格,则他会死亡,游戏结束。
要完成该关卡,Monocarp 的角色必须抵达单元格 (2,n) —— 即第 2 行与第 n 列的交点处。
请帮助 Monocarp 判断是否可能完成该关卡。
输入格式
The first line contains a single integer t (1≤t≤100) — the number of test cases. Then the test cases follow. Each test case consists of three lines.
The first line contains a single integer n (3≤n≤100) — the number of columns.
The next two lines describe the level. The i-th of these lines describes the i-th line of the level — the line consists of the characters '0' and '1'. The character '0' corresponds to a safe cell, the character '1' corresponds to a trap cell.
Additional constraint on the input: cells (1,1) and (2,n) are safe.
第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。随后是各测试用例。每个测试用例由三行组成。
第一行包含一个整数 n(3≤n≤100),表示列数。
接下来的两行描述关卡。这两行中的第 i 行描述关卡的第 i 行,该行由字符 '0' 和 '1' 组成。字符 '0' 表示安全格子,字符 '1' 表示陷阱格子。
输入的额外约束:格子 (1,1) 和 (2,n) 均为安全格子。
输出格式
For each test case, output YES if it is possible to complete the level, and NO otherwise.
对于每个测试用例,如果能够完成该关卡,则输出 YES;否则输出 NO。
输入输出样例
输入#1
4 3 000 000 4 0011 1100 4 0111 1110 6 010101 101010
输出#1
YES YES NO YES
说明/提示
Consider the example from the statement.
In the first test case, one of the possible paths is (1,1)→(2,2)→(2,3).
In the second test case, one of the possible paths is (1,1)→(1,2)→(2,3)→(2,4).
In the fourth test case, one of the possible paths is (1,1)→(2,2)→(1,3)→(2,4)→(1,5)→(2,6).
考虑题目陈述中的示例。
在第一个测试用例中,一条可能的路径是 (1,1)→(2,2)→(2,3)。
在第二个测试用例中,一条可能的路径是 (1,1)→(1,2)→(2,3)→(2,4)。
在第四个测试用例中,一条可能的路径是 (1,1)→(2,2)→(1,3)→(2,4)→(1,5)→(2,6)。
输入解题思路,AI测评打分。不知道怎么写?