A9164 | Ciel and Robot
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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)$ .
- '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)$ .
输入格式
The first line contains two integers $a$ and $b$ , ( $-10^{9}<=a,b<=10^{9}$ ). The second line contains a string $s$ ( $1<=|s|<=100$ , $s$ only contains characters 'U', 'D', 'L', 'R') — the command.
输出格式
Print "Yes" if the robot will be located at $(a,b)$ , and "No" otherwise.
输入输出样例
输入 #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).
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).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted