CodeForces 321 A - Ciel and Robot
2017-06-08 08:59
295 查看
【题目链接】:click here~~
【题目大意】:一个robot 机器人 。能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0)。指令一出。robot会反复行动,推断是否能在无限行动的情况下经过点(n,m)。
【解题思路】事实上细致模拟一下,能够发现是有周期的。推断就可以,见代码吧~~
代码:
【题目大意】:一个robot 机器人 。能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0)。指令一出。robot会反复行动,推断是否能在无限行动的情况下经过点(n,m)。
【解题思路】事实上细致模拟一下,能够发现是有周期的。推断就可以,见代码吧~~
代码:
#include <iostream> #include <algorithm> #include <bits/stdc++.h> using namespace std; const int N=105; int n,m,c,t,ans,res,tmp; char str ; int X ,Y ; int main() { int x,y; while(~scanf("%d%d",&x,&y)) { memset(X,0,sizeof(X)); memset(Y,0,sizeof(Y)); scanf("%s",str+1); int len=strlen(str+1); if(x==0&&y==0){ puts("Yes"); return 0; } else{ bool flag=0; int j=0,xx=x; int yy=y; int uu=0,dd=0,ll=0,rr=0; for(int i=0; i<=len; ++i){ switch (str[i]){ case 'U': X[i]=X[i-1],Y[i]=Y[i-1]+1;///y[0]=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];///X[0]=1, break; } /* if(str[i]=='U') { X[i]=X[i-1],Y[i]=Y[i-1]+1; /// uu++;///yy+=1 } else if(str[i]=='D') { X[i]=X[i-1],Y[i]=Y[i-1]-1; /// dd++;///yy-=1 } else if(str[i]=='L') { X[i]=X[i-1]-1,Y[i]=Y[i-1]; /// ll++;///xx-=1 } else { X[i]=X[i-1]+1,Y[i]=Y[i-1]; ///xx+=1 } */ } int zq; for(int i=0; i<=len; ++i){//2 2 int za=xx-X[i];///2-X[0]=1, int zb=yy-Y[i];///2-Y[0]=1, zq=(X[len]!=0?za/X[len]:(Y[len]!=0? zb/Y[len]:1)); if(X[len]*zq==za&&Y[len]*zq==zb&&zq>=0) ///if(zq>=0){ puts("Yes"); return 0; } } puts("No"); } } return 0; } /* 2 2 RU 1 2 RU -1 1000000000 LRRLU 0 0 D Yes No Yes Yes */
相关文章推荐
- CodeForces 321 A - Ciel and Robot
- Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
- 网络流(费用流)CodeForces 321B:Ciel and Duel
- codeforces 327 A Ciel and Dancing
- CodeForces 748C Santa Claus and Robot (思维)
- codeforces 321E Ciel and Gondolas 四边形不等式
- codeforces 327 A Ciel and Dancing
- CF 322C. Ciel and Robot 枚举+模拟
- CodeForces - 748C Santa Claus and Robot(思维)
- CF 321A(Ciel and Robot-暴力枚举)
- Codeforces 752C Santa Claus and Robot 思维
- 【codeforces 752C】Santa Claus and Robot
- Codeforces 355C Vasya and Robot【贪心+前缀和】
- CodeForces 321 C.Ciel the Commander(树分治)
- Codeforces 355C Vasya and Robot 暴力枚举
- CodeForces 354A - Vasya and Robot 简单思维..赋初值一定不能随便了T_T
- 【Codeforces 748 C Santa Claus and Robot】+ 思维
- 【codeforces 752C】Santa Claus and Robot
- 【Codeforces Round #389】Codeforces 752C Santa Claus and Robot
- CodeForces 354A - Vasya and Robot (简单思维)