CF1791B.Following Directions
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alperen is standing at the point (0,0). He is given a string s of length n and performs n moves. The i-th move is as follows:
- if si=L, then move one unit left;
- if si=R, then move one unit right;
- if si=U, then move one unit up;
- if si=D, then move one unit down.
If Alperen starts at the center point, he can make the four moves shown.
There is a candy at (1,1) (that is, one unit above and one unit to the right of Alperen's starting point). You need to determine if Alperen ever passes the candy.
Alperen's path in the first test case.
阿尔佩伦站在点 (0,0) 处。他获得一个长度为 n 的字符串 s,并执行 n 次移动。第 i 次移动规则如下:
- 若 si=L,则向左移动一个单位;
- 若 si=R,则向右移动一个单位;
- 若 si=U,则向上移动一个单位;
- 若 si=D,则向下移动一个单位。
若阿尔佩伦从中心点出发,可执行图中所示的四种移动。
在点 (1,1)(即阿尔佩伦起始点正上方一个单位、正右方一个单位处)有一颗糖果。你需要判断阿尔佩伦在移动过程中是否曾经过该糖果所在位置。
第一个测试用例中阿尔佩伦的路径。
输入格式
The first line of the input contains an integer t (1≤t≤1000) — the number of testcases.
The first line of each test case contains an integer n (1≤n≤50) — the length of the string.
The second line of each test case contains a string s of length n consisting of characters L, R, D, and U, denoting the moves Alperen makes.
输入的第一行包含一个整数 t(1≤t≤1000)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤50)——字符串的长度。
每个测试用例的第二行包含一个长度为 n 的字符串 s,由字符 L、R、D 和 U 组成,表示 Alperen 所做的移动。
输出格式
For each test case, output "YES" (without quotes) if Alperen passes the candy, and "NO" (without quotes) otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
对于每个测试用例,如果阿尔佩伦传递了糖果,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。
你可以以任意大小写形式输出答案(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答)。
输入输出样例
输入#1
7 7 UUURDDL 2 UR 8 RRRUUDDD 3 LLL 4 DUUR 5 RUDLL 11 LLLLDDRUDRD
输出#1
YES YES NO NO YES YES NO
说明/提示
In the first test case, Alperen follows the path $$(0,0) \overset{\texttt{U}}{\to} (0,1) \overset{\texttt{U}}{\to} (0,2) \overset{\texttt{U}}{\to} (0,3) \overset{\texttt{R}}{\to} (1,3) \overset{\texttt{D}}{\to} (1,2) \overset{\texttt{D}}{\to} \color{green}{\mathbf{(1,1)}} \overset{\texttt{L}}{\to} (0,1).$$ Note that Alperen doesn't need to end at the candy's location of (1,1), he just needs to pass it at some point.
In the second test case, Alperen follows the path $$(0,0) \overset{\texttt{U}}{\to} (0,1) \overset{\texttt{R}}{\to} \color{green}{\mathbf{(1,1)}}.$$
In the third test case, Alperen follows the path $$(0,0) \overset{\texttt{R}}{\to} (1,0) \overset{\texttt{R}}{\to} (2,0) \overset{\texttt{R}}{\to} (3,0) \overset{\texttt{U}}{\to} (3,1) \overset{\texttt{U}}{\to} (3,2) \overset{\texttt{D}}{\to} (3,1) \overset{\texttt{D}}{\to} (3,0) \overset{\texttt{D}}{\to} (3,-1).$$
In the fourth test case, Alperen follows the path $$(0,0) \overset{\texttt{L}}{\to} (-1,0) \overset{\texttt{L}}{\to} (-2,0) \overset{\texttt{L}}{\to} (-3,0).$$
在第一个测试用例中,阿尔佩伦遵循路径
(0,0)→U(0,1)→U(0,2)→U(0,3)→R(1,3)→D(1,2)→D(1,1)→L(0,1).
注意:阿尔佩伦无需最终停在糖果所在位置 (1,1),他只需在某个时刻经过该点即可。
在第二个测试用例中,阿尔佩伦遵循路径
(0,0)→U(0,1)→R(1,1).
在第三个测试用例中,阿尔佩伦遵循路径
(0,0)→R(1,0)→R(2,0)→R(3,0)→U(3,1)→U(3,2)→D(3,1)→D(3,0)→D(3,−1).
在第四个测试用例中,阿尔佩伦遵循路径
(0,0)→L(−1,0)→L(−2,0)→L(−3,0).
输入解题思路,AI测评打分。不知道怎么写?