CF 322C - Ciel and Robot 计算周期
2013-07-12 08:24
621 查看
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.
Sample test(s)
input
output
input
output
input
output
input
output
Note
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).
字符串s能够无限次重复,问能否按照字符串S的指令,从(0,0)移动到(a,b)
只用输出Yes或者No
因为指令S<=100。。就是判断额。。算周期
x[len]*zhouqi + x[i] == a
&& y[len]*zhouqi + y[i] == b
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.
Sample test(s)
input
2 2 RU
output
Yes
input
1 2 RU
output
No
input
-1 1000000000 LRRLU
output
Yes
input
0 0 D
output
Yes
Note
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).
字符串s能够无限次重复,问能否按照字符串S的指令,从(0,0)移动到(a,b)
只用输出Yes或者No
因为指令S<=100。。就是判断额。。算周期
x[len]*zhouqi + x[i] == a
&& y[len]*zhouqi + y[i] == b
/* * @author ipqhjjybj * @date 20130711 * */ #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) int main(){ int a,b; char s[105]; int x[105]={0},y[105]={0}; scanf("%d %d %s",&a,&b,s+1); int len = strlen(s+1); for(int i=1;i<=len;i++){ switch(s[i]){ case 'U':x[i]=x[i-1],y[i]=y[i-1]+1;break; case 'D':x[i]=x[i-1],y[i]=y[i-1]-1;break; case 'L':x[i]=x[i-1]-1,y[i]=y[i-1];break; case 'R':x[i]=x[i-1]+1,y[i]=y[i-1];break; } } int zhouqi; for(int i = 0;i<=len;i++){ int da=a-x[i]; int db=b-y[i]; zhouqi=(x[len]!=0?da/x[len]:(y[len]!=0?db/y[len]:1)); if(zhouqi>=0 &&x[len]*zhouqi==da &&y[len]*zhouqi==db){ printf("Yes\n"); return 0; } } printf("No\n"); return 0; }
相关文章推荐
- CF 322C. Ciel and Robot 枚举+模拟
- CF 321A(Ciel and Robot-暴力枚举)
- Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
- [CF 294D]Shaass and Painter Robot解题报告
- CodeForces 321 A - Ciel and Robot
- CodeForces 321 A - Ciel and Robot
- Codeforces Round #190 (Div. 2)-C. Ciel and Robot
- CF321E Ciel and Gondolas 【决策单调性dp】
- CF 596A. Wilbur and Swimming Pool 【计算矩形面积】
- CF:322D - Ciel and Duel 贪心 或者 DP 我用的贪心 。。难道sort跟qsort是不一样的么?
- cf C. Vasya and Robot
- cf 342C - Cupboard and Balloons(计算几何)
- CF:322D - Ciel and Duel 贪心 或者 DP 我用的贪心 。。难道sort跟qsort是不一样的么?
- [CF 321D]Ciel and Flipboard解题报告
- Ciel and Robot
- upnp(Universal Plug and Play)& IP包生存周期太短
- 测试过程方法论-第三章:附件、需求跟踪、缺陷周期计算
- CF Bear and Game
- selenium webdriver 右键另存为下载文件(结合robot and autoIt)
- CF_6C_Alice,BobAndChocolate