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 ...
随机推荐
- JAVA学习第四十五课 — 其它对象API(一)System、Runtime、Math类
一.System类 1. static long currentTimeMillis() 返回以毫秒为单位的当前时间. 实际上:当前时间与协调世界时 1970 年 1 月 1 日午夜之间的时间差(以毫 ...
- 51nod-1273: 旅行计划
[传送门:51nod-1273] 简要题意: 给出一棵树,点数为n,现在你有一个旅行计划,从k城市出发,每天前往一个没去过的城市,并且旅途中经过的没有去过的城市尽可能的多(如果有2条路线,经过的没有去 ...
- xss 多分类 优选 贝叶斯、逻辑回归、决策树
import re import numpy as np from sklearn import cross_validation from sklearn import datasets from ...
- [Project Euler 409] Nim Extreme 解题报告 (统计方案数)
题目链接:https://projecteuler.net/problem=409 题目: 题解: 题目问你必胜态的数目,我们考虑用总的方案数减去必败态的方案数(NIM游戏没有平局这个操作) 必败态的 ...
- springboot 注入xml自定义类
新建入口类可扫描类: @Configuration @ImportResource(locations = {"classpath:spring-bean.xml"}) publi ...
- POJ 3190 priority_queue 贪心
思路: 贪心?就算是吧 先把所有的开始时间排个序 如果当前的能匹配上已有的牛栏,就找开始时间最早的那个. 否则新加一个牛栏 整个过程用priority_queue实现就OK了.. //By Siriu ...
- List<List<model>>如何更快捷的取里面的model?
访问接口返回数据类型为List<List<model>>,现在想将其中的model插入数据库,感觉一点点循环有点傻,0.0...,各位有没有其他的方法? List<Lis ...
- orac
#!/bin/bash # Copyright (c) 2013, 2016, Liang Guojun. All rights reserved. # Program: # Check ...
- 一张图片让你了解android的事件分发机制
- UE4的JSON读写方式<一>
声明:全部权利保留. 转载必须说明出处:http://blog.csdn.net/cartzhang/article/details/41009343 UE4的Json的解析博客地址: http:// ...