Ciel and Robot
1 second
256 megabytes
standard input
standard output
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all:
- 'U': go up, (x, y) → (x, y+1);
- 'D': go down, (x, y) → (x, y-1);
- 'L': go left, (x, y) → (x-1, y);
- 'R': go right, (x, y) → (x+1, y).
The robot will do the operations in s from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (a, b).
The first line contains two integers a and b, ( - 109 ≤ a, b ≤ 109). The second line contains a string s (1 ≤ |s| ≤ 100, s only contains characters 'U', 'D', 'L', 'R') — the command.
Print "Yes" if the robot will be located at (a, b), and "No" otherwise.
细节蛮多的,做的我好忧伤。。。
#include <iostream>
#include <string>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std; int main()
{
char s[];
int a, b, dx, dy, i;
while(scanf("%d %d", &a, &b) != EOF)
{
scanf("%s", s);
dx = dy = ;
for(i = ; s[i] != '\0'; i++)
{
if(dx == a && dy == b) break;
if(s[i] == 'U') dy++;
else if(s[i] == 'D') dy--;
else if(s[i] == 'L') dx--;
else dx++;
}
if(s[i] == '\0')
{
int dx2 = abs(dx), dy2 = abs(dy);
for(i = ; s[i] != '\0'; i++)
{
if(s[i] == 'U') b--;
else if(s[i] == 'D') b++;
else if(s[i] == 'L') a++;
else a--;
if(!a && !b) break;
int a2 = abs(a), b2 = abs(b);
if((long long)a * dy == (long long)b * dx && (long long)b * dy >= && (long long)a * dx >= )
{
if(dy && dx)
{
if(a2 % dx2 == && b2 % dy2 == ) break;
}
else if(!dx && dy)
{
if(!a && b2 % dy2 == ) break;
}
else if(dx && !dy)
{
if(!b && a2 % dx2 == ) break;
}
}
}
}
if(s[i] != '\0') puts("Yes");
else puts("No");
}
return ;
}

Ciel and Robot的更多相关文章
- CodeForces 321 A - Ciel and Robot
[题目链接]:click here~~ [题目大意]:一个robot 机器人 .能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0).指令一出.robot会反复行动,推断是否能在无限行 ...
- Codeforces Round 190 div.2 322C 321A Ciel and Robot
唔...这题是数学题. 比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交. 思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断 ...
- CodeForces 321A Ciel and Robot(数学模拟)
题目链接:http://codeforces.com/problemset/problem/321/A 题意:在一个二维平面中,開始时在(0,0)点,目标点是(a.b),问能不能通过反复操作题目中的指 ...
- CodeForces 321A
A. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #190 (Div. 1 + Div. 2)
A. Ciel and Dancing 模拟. B. Ciel and Flowers 混合类型的数量只能为0.1.2,否则3个可以分成各种类型各自合成. C. Ciel and Robot 考虑一组 ...
- Robot Framework用户手册 (版本:3.0)
版权信息:诺基亚网络和解决中心 本翻译尊重原协议,仅用于个人学习使用 1.开始: 1.1 介绍: Robot Framework是一个基于Python的,为终端测试和验收驱动开发(ATDD)的可扩展的 ...
- selenium webdriver 右键另存为下载文件(结合robot and autoIt)
首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...
- RIDE -- Robot Framework setup
RobotFramework 是一款基于python 的可以实现关键字驱动和数据驱动并能够生成比较漂亮的测试报告的一款测试框架 这里使用的环境是 python-2.7.10.amd64.msi RID ...
- [8.2] Robot in a Grid
Imagine a robot sitting on the upper left corner of grid with r rows and c columns. The robot can on ...
随机推荐
- 【转】关于KDD Cup '99 数据集的警告,希望从事相关工作的伙伴注意
Features From: Terry Brugger Date: 15 Sep 2007 Subject: KDD Cup '99 dataset (Network Intrusion) cons ...
- java 数据类型
java是一个静态类型的语言,所有的数据类型都是有类型的(强类型的语言),当一个变量名指定类型后不可再改变变量类型 数据类型包括基本数据类型和引用数据类型(除基本数据类型外的其他类型都是引用数据类型) ...
- atitit.提升开发效率---动态语言总结
atitit.提升开发效率---动态语言总结 ruby,python 都不错,就是语法不好, 应用不广泛,文档,工具都非常少,不推荐... php狠不错,就是高级特性不行.. 看来子有.net/jav ...
- java 初学者需注意问题
1.Java为什么能跨平台运行? Java语言编写的程序既是编译型的,又是解释型的.程序代码经过编译之后转换为一种Java字节码的中间语言,Java虚拟机即JVM将对字节码进行解释和运行.编译只进行一 ...
- Activiti 流程实例、任务、执行对象及相关的表
一个流程中,流程实例只有一个,执行对象可以有多个(如果存在分支和聚合) SELECT * FROM activiti.act_ru_execution a; #正在执行的执行对象表 SELECT * ...
- NoteExpress 自定义参考文献输出样式
最近在写硕士论文,样式中没有符合要求的,于是就自己来编辑下样式文件,下文是网上搜集的关于自定义参考文献的一篇教程,可以参考. 一.分隔符|和连接符*的使用 (1)连接符 * 主要作用是“建立依赖关系” ...
- HTML 邮件链接,超链接发邮件
在网页中可以设置如“联系我们”.“问题反馈”等所谓的邮箱链接,类似网页超链接,只是可以直接打开默认邮箱程序. 使用<a href="mailto:youEMail@xxx.yyy&qu ...
- 解决Visual Studio 2010/2012的RC4011 warnings
如果在vc10/11工程的rc文件中有以下任意一行代码: #include <winuser.h> #include <richedit.h> 那么vc将会给出一对警告: C: ...
- Android版-支付宝APP支付
此项目已开源 赶快来围观 Start支持下吧 [客户端开源地址-JPay][服务端端开源地址-在com.javen.alipay 包名下] 上一篇详细介绍了微信APP支付 点击这里 此篇文章来详细介绍 ...
- IOC性能对比