CF1680B.Robots
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a field divided into n rows and m columns. Some cells are empty (denoted as E), other cells contain robots (denoted as R).
You can send a command to all robots at the same time. The command can be of one of the four types:
- move up;
- move right;
- move down;
- move left.
When you send a command, all robots at the same time attempt to take one step in the direction you picked. If a robot tries to move outside the field, it explodes; otherwise, every robot moves to an adjacent cell in the chosen direction.
You can send as many commands as you want (possibly, zero), in any order. Your goal is to make at least one robot reach the upper left corner of the field. Can you do this without forcing any of the robots to explode?
有一个被划分为 n 行 m 列的场地。某些格子为空(记为 E),其余格子中放置有机器人(记为 R)。
你可以同时向所有机器人发送一条指令。该指令可以是以下四种类型之一:
- 向上移动;
- 向右移动;
- 向下移动;
- 向左移动。
当你发送一条指令时,所有机器人会同时尝试朝你指定的方向迈出一步。若某个机器人试图移出场地边界,则它将爆炸;否则,每个机器人都会移动到所选方向上的相邻格子中。
你可以发送任意多条指令(可能为零条),且顺序任意。你的目标是让至少一个机器人抵达场地的左上角。你能否在不导致任何机器人爆炸的前提下实现这一目标?
输入格式
The first line contains one integer t (1≤t≤5000) — the number of test cases.
Each test case starts with a line containing two integers n and m (1≤n,m≤5) — the number of rows and the number of columns, respectively. Then n lines follow; each of them contains a string of m characters. Each character is either E (empty cell} or R (robot).
Additional constraint on the input: in each test case, there is at least one robot on the field.
第一行包含一个整数 t(1≤t≤5000)—— 测试用例的数量。
每个测试用例以一行开始,该行包含两个整数 n 和 m(1≤n,m≤5)—— 分别表示行数和列数。随后是 n 行;每行包含一个长度为 m 的字符串。每个字符为 E(空单元格)或 R(机器人)。
输入的附加约束:在每个测试用例中,场地中至少有一个机器人。
输出格式
If it is possible to make at least one robot reach the upper left corner of the field so that no robot explodes, print YES. Otherwise, print NO.
如果可以让至少一个机器人到达场地的左上角且不发生爆炸,则输出 YES;否则输出 NO。
输入输出样例
输入#1
6 1 3 ERR 2 2 ER RE 2 2 ER ER 1 1 R 4 3 EEE EEE ERR EER 3 3 EEE EER REE
输出#1
YES NO YES YES YES NO
说明/提示
Explanations for test cases of the example:
- in the first test case, it is enough to send a command to move left.
- in the second test case, if you try to send any command, at least one robot explodes.
- in the third test case, it is enough to send a command to move left.
- in the fourth test case, there is already a robot in the upper left corner.
- in the fifth test case, the sequence "move up, move left, move up" leads one robot to the upper left corner;
- in the sixth test case, if you try to move any robot to the upper left corner, at least one other robot explodes.
示例测试用例的解释:
- 在第一个测试用例中,仅需发送一条向左移动的指令即可。
- 在第二个测试用例中,若尝试发送任何指令,则至少有一个机器人会爆炸。
- 在第三个测试用例中,仅需发送一条向左移动的指令即可。
- 在第四个测试用例中,左上角已存在一个机器人。
- 在第五个测试用例中,指令序列“向上移动,向左移动,向上移动”可使一个机器人抵达左上角;
- 在第六个测试用例中,若尝试将任一机器人移至左上角,则至少有另一个机器人会爆炸。
输入解题思路,AI测评打分。不知道怎么写?