#abc291c. C - LRUD Instructions 2
C - LRUD Instructions 2
Score : points
问题描述
Takahashi在一个二维平面上,从原点出发,他进行了 次移动。
这 次移动由长度为 的字符串 表示,如下所示:
-
Takahashi在第 次移动后的坐标是:
- 如果第 个字符为
R
,则坐标为 ; - 如果第 个字符为
L
,则坐标为 ; - 如果第 个字符为
U
,则坐标为 ; - 如果第 个字符为
D
,则坐标为 ,
- 如果第 个字符为
其中 是他在移动前的坐标。
确定在 次移动的过程中(包括起点和终点),Takahashi是否多次访问过相同的坐标。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi is on a two-dimensional plane. Starting from the origin, he made moves.
The moves are represented by a string of length as described below:
-
Takahashi's coordinates after the -th move are:
- if the -th character of is
R
; - if the -th character of is
L
; - if the -th character of is
U
; and - if the -th character of is
D
,
where is his coordinates before the move.
- if the -th character of is
Determine if Takahashi visited the same coordinates multiple times in the course of the moves (including the starting and ending points).
Constraints
- is an integer.
- is a string of length consisting of
R
,L
,U
, andD
.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if Takahashi visited the same coordinates multiple times in the course of the moves; print No
otherwise.
Sample Input 1
5
RLURU
Sample Output 1
Yes
Takahashi's coordinates change as follows: .
Sample Input 2
20
URDDLLUUURRRDDDDLLLL
Sample Output 2
No
update @ 2024/3/10 12:08:38