CF321A.Ciel and Robot
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all:
- 'U': go up, (x, y) → (x, y+1);
- 'D': go down, (x, y) → (x, y-1);
- 'L': go left, (x, y) → (x-1, y);
- 'R': go right, (x, y) → (x+1, y).
The robot will do the operations in s from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (a, b).
狐狸雪莉在二维平面上有一个机器人。初始时,它位于点 (0,0)。雪莉为机器人编写了一条指令,该指令用字符串 s 表示。s 的每个字符代表一次移动操作。总共有四种移动操作:
'U':向上移动,(x,y)→(x,y+1);'D':向下移动,(x,y)→(x,y−1);'L':向左移动,(x,y)→(x−1,y);'R':向右移动,(x,y)→(x+1,y)。
机器人将从左到右依次执行 s 中的操作,并无限次重复该指令序列。请帮助狐狸雪莉判断:是否存在某个时刻,机器人恰好位于点 (a,b)。
输入格式
The first line contains two integers a and b, ( - 109 ≤ a, b ≤ 109). The second line contains a string s (1 ≤ |s| ≤ 100, s only contains characters 'U', 'D', 'L', 'R') — the command.
第一行包含两个整数 a 和 b(−109≤a,b≤109)。
第二行包含一个字符串 s(1≤∣s∣≤100,s 仅由字符 'U'、'D'、'L'、'R' 组成)—— 表示指令。
输出格式
Print "Yes" if the robot will be located at (a, b), and "No" otherwise.
如果机器人最终位于点 (a,b),则输出“Yes”;否则输出“No”。
输入输出样例
输入#1
2 2 RU
输出#1
Yes
输入#2
1 2 RU
输出#2
No
输入#3
-1 1000000000 LRRLU
输出#3
Yes
输入#4
0 0 D
输出#4
Yes
说明/提示
In the first and second test case, command string is "RU", so the robot will go right, then go up, then right, and then up and so on.
The locations of its moves are (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) → ...
So it can reach (2, 2) but not (1, 2).
在第一个和第二个测试用例中,命令字符串为 "RU",因此机器人将先向右移动,再向上移动,然后再次向右移动,再向上移动,依此类推。
其移动位置依次为:
(0,0)→(1,0)→(1,1)→(2,1)→(2,2)→⋯
因此,它可以到达点 (2,2),但无法到达点 (1,2)。
输入解题思路,AI测评打分。不知道怎么写?