CodeForces 321 A - Ciel and Robot
【题目链接】: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的更多相关文章
- Ciel and Robot
C. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces 321A Ciel and Robot(数学模拟)
题目链接:http://codeforces.com/problemset/problem/321/A 题意:在一个二维平面中,開始时在(0,0)点,目标点是(a.b),问能不能通过反复操作题目中的指 ...
- Codeforces Round 190 div.2 322C 321A Ciel and Robot
唔...这题是数学题. 比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交. 思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断 ...
- Codeforces 752C - Santa Claus and Robot - [简单思维题]
题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...
- 网络流(费用流)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: ...
- codeforces #321 DIV2
A题: 链接:http://codeforces.com/contest/580/problem/A dp,最长连续不上升子序列 #include<iostream> #include&l ...
- Codeforces 294D - Shaass and Painter Robot
294D - Shaass and Painter Robot 思路: 可以用数学归纳法证明一个结论:整个棋盘黑白相间当且仅当边缘黑白相间. 分奇偶讨论又可得出边缘黑色格个数为n+m-2 这样就可以暴 ...
- Codeforces 1073C:Vasya and Robot(二分)
C. Vasya and Robot time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard ...
- CodeForces 620A Professor GukiZ's Robot
水题 #include<cstdio> #include<cstring> #include<cmath> #include<stack> #inclu ...
随机推荐
- tp5实现多数据库查询
引言: 有时候一个管理后台,需要涉及到多个数据库.比如,商城管理.直播管理.消息管理等等,它们都有自己的数据库.这个时候,就需要去连接多个数据库,进行处理了.thinkphp可以支持多个数据库连接. ...
- 7.配置文件mocha.opts
转自:http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html Mocha允许在test目录下面,放置配置文件m ...
- 实时监控Cat之旅~对Get和Post进行封装,支持分布式消息树
对第三方接口的调用我们需要对GET和POST进行监控,看一些请求的执行是否成功,如A调用B,B调用C,C调用D,这一连串的东西需要我们使用cat进行记录,进行记录之后,我们可以很容易的发现请求响应的时 ...
- python3.x学习笔记3(基础知识)
1.集合集合是一个无序的,不重复的数据组合,作用如下: >>去重,把一个列表变成集合,就自动去重 >>关系测试,测试两组数据之前的交集.差集.并集等关系 2.关系运算 交集: ...
- js thousand separator and change td content
js thousand seprator and change TD content // integer function addCommas(n){ })/; return String(n).r ...
- Audio / Video Playback
For Developers > Design Documents > Audio / Video Playback Interested in helping out? Ch ...
- XRDP与VNC的关系(转载)
XRDP与VNC的关系 如果仅仅安装XRDP协议.是不能在windows上使用远程桌面连接到Ubuntu. 还须要安装VNCServer才行. 所以,XRDP启动之后.系统会自己主动启动一个VNC会话 ...
- 超链接:a标签
a标签的功能:实现跳转功能 a标签的重要属性:href,target href的值为跳转目标的地址,如果是跳转页面的话,需要这个页面的超链接. target的值有四个:_blank._self._pa ...
- POJ 3630 Phone List(字典树)
题意 题意:t个case(1<=t<=40),给你n个电话号码(电话号码长度<10)(1 ≤ n ≤ 10000),如果有电话号码是另一个电话号码的前缀,则称这个通讯录是不相容的,判 ...
- MySql系列之单表查询
单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 关键字的执行 ...