C. Ciel and Robot
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputFox 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).
Input
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.
Output
Print "Yes" if the robot will be located at (a, b), and "No" otherwise.
细节蛮多的,做的我好忧伤。。。
1 #include <iostream> 2 #include <string> 3 #include <map> 4 #include <cstdio> 5 #include <cmath> 6 #include <cstring> 7 using namespace std; 8 9 int main() 10 { 11 char s[101]; 12 int a, b, dx, dy, i; 13 while(scanf("%d %d", &a, &b) != EOF) 14 { 15 scanf("%s", s); 16 dx = dy = 0; 17 for(i = 0; s[i] != '