Ciel and Robot
2013-08-07 01:12
260 查看
C. Ciel and Robot
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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).
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.
细节蛮多的,做的我好忧伤。。。
View Code
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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).
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.
细节蛮多的,做的我好忧伤。。。
#include <iostream> #include <string> #include <map> #include <cstdio> #include <cmath> #include <cstring> using namespace std; int main() { char s[101]; int a, b, dx, dy, i; while(scanf("%d %d", &a, &b) != EOF) { scanf("%s", s); dx = dy = 0; for(i = 0; s[i] != '\0'; i++) { if(dx == a && dy == b) break; if(s[i] == 'U') dy++; else if(s[i] == 'D') dy--; else if(s[i] == 'L') dx--; else dx++; } if(s[i] == '\0') { int dx2 = abs(dx), dy2 = abs(dy); for(i = 0; s[i] != '\0'; i++) { if(s[i] == 'U') b--; else if(s[i] == 'D') b++; else if(s[i] == 'L') a++; else a--; if(!a && !b) break; int a2 = abs(a), b2 = abs(b); if((long long)a * dy == (long long)b * dx && (long long)b * dy >= 0 && (long long)a * dx >= 0) { if(dy && dx) { if(a2 % dx2 == 0 && b2 % dy2 == 0) break; } else if(!dx && dy) { if(!a && b2 % dy2 == 0) break; } else if(dx && !dy) { if(!b && a2 % dx2 == 0) break; } } } } if(s[i] != '\0') puts("Yes"); else puts("No"); } return 0; }
View Code
![](http://images.cnitblog.com/blog/404034/201308/07011230-ff524af74bf446509a889eb456ed8e8e.jpg)
相关文章推荐
- Codeforces Round #190 (Div. 2)-C. Ciel and Robot
- CF 321A(Ciel and Robot-暴力枚举)
- CF 322C - Ciel and Robot 计算周期
- CodeForces 321 A - Ciel and Robot
- CodeForces 321 A - Ciel and Robot
- Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
- CF 322C. Ciel and Robot 枚举+模拟
- Vasya and Robot
- codeforces748c-Santa Claus and Robot
- CF321E Ciel and Gondolas 【决策单调性dp】
- [robot]Quaternions and Rigid Transformations
- Shaass and Painter Robot : CodeForces294D
- Codeforces Round #190 DIV.2 A. Ciel and Dancing
- Robot Framework and Ride
- 【Codeforces Round #389】Codeforces 752C Santa Claus and Robot
- Codeforces Round #206 (Div. 2) C-Vasya and Robot
- 用于远程教育和培训的ROS机器人在线编程(ROS-based Online Robot Programming for Remote Education and Training)
- A. Ciel and Dancing
- Codeforces 355C Vasya and Robot 暴力枚举
- Robot Framework and Ride