题目链接】: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
*/

最新文章

  1. React Native知识10-ListView组件
  2. @helper函数使用方法
  3. this.getServletContext().getRealPath(&quot;WEB-INF&quot;);
  4. ID3算法
  5. Linux prerouting和postrouting的区别
  6. Powershell连接Office 365各组件的方法
  7. iOS之上线被拒
  8. nodebb在阿里云主机部署过程
  9. tomcat线程数查看
  10. EXP/IMP 命令参数
  11. linux开放80 端口
  12. SSH 远程登陆
  13. iOS - is missing from working copy
  14. ln -s 软连接介绍
  15. 你应该知道Go语言的几个优势
  16. CentOS下使用autoenv实现进入特定目录后运行特定环境变量
  17. HttpClient 学习整理【转】
  18. caffe2安装教程
  19. Android LayerDrawable资源应用
  20. 【STSRM12】整除

热门文章

  1. 51nod-1273: 旅行计划
  2. WAF——针对Web应用发起的攻击,包括但不限于以下攻击类型:SQL注入、XSS跨站、Webshell上传、命令注入、非法HTTP协议请求、非授权文件访问等
  3. Struts2 | struts.xml文件中使用method属性和通配符简化action标签和Action处理类的编写
  4. Python 序列化处理
  5. jquery批量绑定click事件
  6. jqueryValidator自定义校验规则的一种方式(不覆盖源码)
  7. P1452 Beauty Contes
  8. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(2)
  9. js相关禁止
  10. grvphviz &amp;&amp; dot脚本语言