CodeForces 321 A - Ciel and Robot
2024-08-31 15:32:55
【题目链接】: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
*/
最新文章
- React Native知识10-ListView组件
- @helper函数使用方法
- this.getServletContext().getRealPath(";WEB-INF";);
- ID3算法
- Linux prerouting和postrouting的区别
- Powershell连接Office 365各组件的方法
- iOS之上线被拒
- nodebb在阿里云主机部署过程
- tomcat线程数查看
- EXP/IMP 命令参数
- linux开放80 端口
- SSH 远程登陆
- iOS - is missing from working copy
- ln -s 软连接介绍
- 你应该知道Go语言的几个优势
- CentOS下使用autoenv实现进入特定目录后运行特定环境变量
- HttpClient 学习整理【转】
- caffe2安装教程
- Android LayerDrawable资源应用
- 【STSRM12】整除
热门文章
- 51nod-1273: 旅行计划
- WAF——针对Web应用发起的攻击,包括但不限于以下攻击类型:SQL注入、XSS跨站、Webshell上传、命令注入、非法HTTP协议请求、非授权文件访问等
- Struts2 | struts.xml文件中使用method属性和通配符简化action标签和Action处理类的编写
- Python 序列化处理
- jquery批量绑定click事件
- jqueryValidator自定义校验规则的一种方式(不覆盖源码)
- P1452 Beauty Contes
- PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(2)
- js相关禁止
- grvphviz &;&; dot脚本语言