310160: CF1791B. Following Directions

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

Description

Following Directions

题意翻译

你站在平面直角坐标系的原点 $(0,0)$,给出一个长度为 $n (1 \leq n \leq 50)$ 的字符串 $s$,你移动了 $n$ 次(你始终面向 $y$ 轴正方向),第 $i (1 \leq i \leq n)$次移动具体如下: - 若 $s_i=L$,向左移动一个单位。 - 若 $s_i=R$,向右移动一个单位。 - 若 $s_i=U$,向上移动一个单位。 - 若 $s_i=D$,向下移动一个单位。 现在问题是你是否经过了点 $(1,1)$,经过了输出 `YES`,没有经过输出 `NO`(大小写不敏感)。 有 $t(1 \leq t \leq 1000)$ 组数据。

题目描述

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 $ s_i = \texttt{L} $ , then move one unit left; - if $ s_i = \texttt{R} $ , then move one unit right; - if $ s_i = \texttt{U} $ , then move one unit up; - if $ s_i = \texttt{D} $ , then move one unit down. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1791B/f7080a9f921542de4115442759a59ebc8f7f4033.png) 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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1791B/2e0273962ce58884c74304276d5024743c50c413.png) Alperen's path in the first test case.

输入输出格式

输入格式


The first line of the input contains an integer $ t $ ( $ 1 \leq t \leq 1000 $ ) — the number of testcases. The first line of each test case contains an integer $ n $ ( $ 1 \leq n \leq 50 $ ) — the length of the string. The second line of each test case contains a string $ s $ of length $ n $ consisting of characters $ \texttt{L} $ , $ \texttt{R} $ , $ \texttt{D} $ , and $ \texttt{U} $ , denoting the moves Alperen makes.

输出格式


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).

输入输出样例

输入样例 #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.</p><p>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)}}. $ $ </p><p>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). $ $ </p><p>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). $ $

Input

题意翻译

你站在平面直角坐标系的原点 $(0,0)$,给出一个长度为 $n (1 \leq n \leq 50)$ 的字符串 $s$,你移动了 $n$ 次(你始终面向 $y$ 轴正方向),第 $i (1 \leq i \leq n)$次移动具体如下: - 若 $s_i=L$,向左移动一个单位。 - 若 $s_i=R$,向右移动一个单位。 - 若 $s_i=U$,向上移动一个单位。 - 若 $s_i=D$,向下移动一个单位。 现在问题是你是否经过了点 $(1,1)$,经过了输出 `YES`,没有经过输出 `NO`(大小写不敏感)。 有 $t(1 \leq t \leq 1000)$ 组数据。

Output

**题意翻译**

你站在平面直角坐标系的原点 $(0,0)$,给出一个长度为 $n (1 \leq n \leq 50)$ 的字符串 $s$,你移动了 $n$ 次(你始终面向 $y$ 轴正方向),第 $i (1 \leq i \leq n)$次移动具体如下:

- 若 $s_i=L$,向左移动一个单位。
- 若 $s_i=R$,向右移动一个单位。
- 若 $s_i=U$,向上移动一个单位。
- 若 $s_i=D$,向下移动一个单位。

现在问题是你是否经过了点 $(1,1)$,经过了输出 `YES`,没有经过输出 `NO`(大小写不敏感)。

有 $t(1 \leq t \leq 1000)$ 组数据。

**输入输出格式**

**输入格式**

第一行包含一个整数 $t$ ($1 \leq t \leq 1000$) —— 测试用例的数量。

每个测试用例的第一行包含一个整数 $n$ ($1 \leq n \leq 50$) —— 字符串的长度。

每个测试用例的第二行包含一个长度为 $n$ 的字符串 $s$,由字符 $\texttt{L}$, $\texttt{R}$, $\texttt{D}$, 和 $\texttt{U}$ 组成,表示 Alperen 的移动。

**输出格式**

对于每个测试用例,如果 Alperen 经过点 $(1,1)$,输出 "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
```**题意翻译** 你站在平面直角坐标系的原点 $(0,0)$,给出一个长度为 $n (1 \leq n \leq 50)$ 的字符串 $s$,你移动了 $n$ 次(你始终面向 $y$ 轴正方向),第 $i (1 \leq i \leq n)$次移动具体如下: - 若 $s_i=L$,向左移动一个单位。 - 若 $s_i=R$,向右移动一个单位。 - 若 $s_i=U$,向上移动一个单位。 - 若 $s_i=D$,向下移动一个单位。 现在问题是你是否经过了点 $(1,1)$,经过了输出 `YES`,没有经过输出 `NO`(大小写不敏感)。 有 $t(1 \leq t \leq 1000)$ 组数据。 **输入输出格式** **输入格式** 第一行包含一个整数 $t$ ($1 \leq t \leq 1000$) —— 测试用例的数量。 每个测试用例的第一行包含一个整数 $n$ ($1 \leq n \leq 50$) —— 字符串的长度。 每个测试用例的第二行包含一个长度为 $n$ 的字符串 $s$,由字符 $\texttt{L}$, $\texttt{R}$, $\texttt{D}$, 和 $\texttt{U}$ 组成,表示 Alperen 的移动。 **输出格式** 对于每个测试用例,如果 Alperen 经过点 $(1,1)$,输出 "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 ```

加入题单

算法标签: