题目链接】:click here~~

题目大意】:一个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[N];
int X[N],Y[N]; 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的更多相关文章

  1. Ciel and Robot

    C. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. CodeForces 321A Ciel and Robot(数学模拟)

    题目链接:http://codeforces.com/problemset/problem/321/A 题意:在一个二维平面中,開始时在(0,0)点,目标点是(a.b),问能不能通过反复操作题目中的指 ...

  3. Codeforces Round 190 div.2 322C 321A Ciel and Robot

    唔...这题是数学题. 比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交. 思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断 ...

  4. Codeforces 752C - Santa Claus and Robot - [简单思维题]

    题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...

  5. 网络流(费用流)CodeForces 321B:Ciel and Duel

    Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: ...

  6. codeforces #321 DIV2

    A题: 链接:http://codeforces.com/contest/580/problem/A dp,最长连续不上升子序列 #include<iostream> #include&l ...

  7. Codeforces 294D - Shaass and Painter Robot

    294D - Shaass and Painter Robot 思路: 可以用数学归纳法证明一个结论:整个棋盘黑白相间当且仅当边缘黑白相间. 分奇偶讨论又可得出边缘黑色格个数为n+m-2 这样就可以暴 ...

  8. Codeforces 1073C:Vasya and Robot(二分)

    C. Vasya and Robot time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard ...

  9. CodeForces 620A Professor GukiZ's Robot

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<stack> #inclu ...

随机推荐

  1. LINUX 代码运行时间计算

    clock_gettime比gettimeofday更加精确简单做了一下测试 #include<time.h>#include<stdio.h> #define MILLION ...

  2. vim 插件之supertab

    supertab.vim 这个插件是用来把tab键作为只能补全的映射,当然,具体更能肯定不仅仅只是如此,等待以后发现吧 地址 http://github.com/ervandew/supertab h ...

  3. sklearn 词袋 CountVectorizer

    from sklearn.feature_extraction.text import CountVectorizer texts=["dog cat fish","do ...

  4. 使用Onedrive

    买了个某捷的大硬盘,于是发现比较坑,非要用云存储才能获得额外200G.于是费了一个多小时.不过学习到了很多. 首先硬盘下会给出对应的exe文件,点击运行就可以. 之后注册希捷的账号,以及微软的账号. ...

  5. 使用google API之前需要對input 做什麼 安全性的處理?

    我正要使用node.js 和 google map api做一个小应用,Google MAP API的使用URL如下: https://maps.googleapis.com/maps/api/pla ...

  6. PostgreSQL Replication之第八章 与pgbouncer一起工作(1)

    当您在使用大规模的设施工作,可能有时候,您必须处理许多并发打开的连接.没有人会使用十台服务器来为两个并发用户提供服务--在许多情况下,这根本没有意义.大量的设施通常会处理成百上千的并发连接.引入连接池 ...

  7. ubuntu重启网络报错

    执行:gw@ubuntu:/$ /etc/init.d/networking restart 报错:stop: Rejected send message, 1 matched rules; type ...

  8. 紫书 例题 10-13 UVa 830(递推)

    首先我们按照这三个U的位置来分类,当前三个U在i,i+1, i+2. 那么先看三个U前面,前面不能有三个U,因为我们不能重复计算 那么就是所有的组合减去有U的情况 为了叙述方便,我们设答案为f(n), ...

  9. 紫书 例题 10-8 UVa 1262 (暴力枚举)

    递归一遍遍历所有情况就ok了 #include<cstdio> #include<cstring> #define REP(i, a, b) for(int i = (a); ...

  10. P2633 Count on a tree(主席树)

    题目描述 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始为0,即第一个 ...