题目链接】: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. phpcms v9会员推荐位

    模版显示推荐会员代码 <div class="zhanxun2">             <div class="title">   ...

  2. 使用深度学习检测DGA(域名生成算法)——LSTM的输入数据本质上还是词袋模型

    from:http://www.freebuf.com/articles/network/139697.html DGA(域名生成算法)是一种利用随机字符来生成C&C域名,从而逃避域名黑名单检 ...

  3. python3.x学习笔记3(基础知识)

    1.集合集合是一个无序的,不重复的数据组合,作用如下: >>去重,把一个列表变成集合,就自动去重 >>关系测试,测试两组数据之前的交集.差集.并集等关系 2.关系运算 交集: ...

  4. 《剑指offer》跳台阶

    一.题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 二.输入描述 输入n级台阶 三.输出描述 输出总有多少种不同跳法 四.牛客网提供的框架 cla ...

  5. 51Nod 1433 0和5(数论)

    小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5.小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数.使得这个数尽可能大,而且可以被90整除. 注意: 1.这个数没有前 ...

  6. ECNUOJ 2144 抗震机械制造

    抗震机械制造 Time Limit:1000MS Memory Limit:65536KBTotal Submit:312 Accepted:78 Description  为了应付可能到来的地震,E ...

  7. 《Java并发编程实战》第五章 同步容器类 读书笔记

    一.同步容器类 1. 同步容器类的问题 线程容器类都是线程安全的.可是当在其上进行符合操作则须要而外加锁保护其安全性. 常见符合操作包括: . 迭代 . 跳转(依据指定顺序找到当前元素的下一个元素) ...

  8. Linux Sendfile 的优势

    Sendfile 函数在两个文件描写叙述符之间直接传递数据(全然在内核中操作,传送),从而避免了内核缓冲区数据和用户缓冲区数据之间的拷贝,操作效率非常高,被称之为零拷贝. Sendfile 函数的定义 ...

  9. vue20 父子组件数据交互

    子组件使用父组件数据 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  10. 静态时序分析SAT

    1.   背景 静态时序分析的前提就是设计者先提出要求,然后时序分析工具才会根据特定的时序模型进行分析,给出正确是时序报告. 进行静态时序分析,主要目的就是为了提高系统工作主频以及增加系统的稳定性.对 ...