CF 321A(Ciel and Robot-暴力枚举)
2013-06-29 17:13
441 查看
A. 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 strings. 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).
大致思路:
机器人必然走n个循环+1段
所以只要暴力枚举段
设到第i步时机器人在(xi,yi)
则xt=t*xn+xi yt=t*yn+yi
乱搞即可……
过了Present Test(好激动!数回Div2 只做2题的菜)
结果Final Wa 了……
//我是白痴……
经鉴定,是我68行把||打成了&&……
我的Div 1 啊!!!!!!!!
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/crazy.gif)
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 strings. 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).
大致思路:
机器人必然走n个循环+1段
所以只要暴力枚举段
设到第i步时机器人在(xi,yi)
则xt=t*xn+xi yt=t*yn+yi
乱搞即可……
过了Present Test(好激动!数回Div2 只做2题的菜)
结果Final Wa 了……
//我是白痴……
经鉴定,是我68行把||打成了&&……
我的Div 1 啊!!!!!!!!
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/crazy.gif)
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<functional> #include<iostream> #include<cmath> #include<cctype> #include<ctime> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Lson (x<<1) #define Rson ((x<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define MAXN (50000+10) long long mul(long long a,long long b){return (a*b)%F;} long long add(long long a,long long b){return (a+b)%F;} long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;} typedef long long ll; ll a,b; int n; char s[1000]; int x[1000],y[1000]; int main() { // freopen("robot.in","r",stdin); // freopen(".out","w",stdout); cin>>a>>b; scanf("%s",s+1);n=strlen(s+1); x[0]=y[0]=0; bool bo=0; For(i,n) { if (s[i]=='R') x[i]=x[i-1]+1,y[i]=y[i-1]; if (s[i]=='L') x[i]=x[i-1]-1,y[i]=y[i-1]; if (s[i]=='U') x[i]=x[i-1],y[i]=y[i-1]+1; if (s[i]=='D') x[i]=x[i-1],y[i]=y[i-1]-1; if (x[i]==a&&y[i]==b) bo=1; } if (bo==1) { cout<<"Yes"<<endl; return 0; } Rep(i,n+1) { int t1=a-x[i],t2=b-y[i]; if (t1!=0&&x ==0) continue; if (t2!=0&&y ==0) continue; if (x ==0||y ==0) { bool bo1=0,bo2=0; if (x ==0) bo1=1; if (y ==0) bo2=1; if (bo1&&!bo2) if (t2%y ==0&&t2/y >=0) {cout<<"Yes"<<endl;return 0;} else continue; if (!bo1&&bo2) if (t1%x ==0&&t1/x >=0) {cout<<"Yes"<<endl;return 0;} else continue; if (!x[i]&&!y[i]) {cout<<"Yes"<<endl;return 0;} else continue; } if (t1%x ||t2%y ) continue; t1/=x ,t2/=y ; if (t1<0||t2<0||t1^t2) continue; cout<<"Yes"<<endl; return 0; } cout<<"No"<<endl; return 0; }
相关文章推荐
- Borya and Hanabi - CF#253 (Div. 2)C (442A) 状压暴力枚举
- Codeforces 355C Vasya and Robot 暴力枚举
- CF 322C - Ciel and Robot 计算周期
- CF 322C. Ciel and Robot 枚举+模拟
- Codeforces #410(div2) B. Mike and strings (暴力枚举
- [CF798B] Mike and strings(暴力)
- CF 205 CLittle Elephant and Interval 分类讨论(计数) D(暴力,水题)
- SCU 4489 misaka and last order(暴力枚举)
- codeforces877B(div2)Nikita and string 暴力枚举+前缀和
- [Codeforces673C]Bear and Colors(枚举,暴力)
- codeforces 908 C. New Year and Curling【暴力枚举+图解】
- CF 557C(Arthur and Table-直接暴力)
- SCU 4489 misaka and last order(暴力枚举)
- UVA 10825 Anagram and Multiplication(暴力枚举)
- CF 558A(Lala Land and Apple Trees-暴力)
- cf Petya and Exam(暴力)
- HDU 5944 Fxx and string(暴力/枚举)
- 暴力枚举 C. Arthur and Table
- 枚举暴力 cf B. Preparing Olympiad
- Codeforces #325 B. Laurenty and Shop (暴力枚举)