C. Ciel and Robot
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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).

Input

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.

Output

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的更多相关文章

  1. CodeForces 321 A - Ciel and Robot

    [题目链接]:click here~~ [题目大意]:一个robot 机器人 .能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0).指令一出.robot会反复行动,推断是否能在无限行 ...

  2. Codeforces Round 190 div.2 322C 321A Ciel and Robot

    唔...这题是数学题. 比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交. 思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断 ...

  3. CodeForces 321A Ciel and Robot(数学模拟)

    题目链接:http://codeforces.com/problemset/problem/321/A 题意:在一个二维平面中,開始时在(0,0)点,目标点是(a.b),问能不能通过反复操作题目中的指 ...

  4. CodeForces 321A

    A. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces Round #190 (Div. 1 + Div. 2)

    A. Ciel and Dancing 模拟. B. Ciel and Flowers 混合类型的数量只能为0.1.2,否则3个可以分成各种类型各自合成. C. Ciel and Robot 考虑一组 ...

  6. Robot Framework用户手册 (版本:3.0)

    版权信息:诺基亚网络和解决中心 本翻译尊重原协议,仅用于个人学习使用 1.开始: 1.1 介绍: Robot Framework是一个基于Python的,为终端测试和验收驱动开发(ATDD)的可扩展的 ...

  7. selenium webdriver 右键另存为下载文件(结合robot and autoIt)

    首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...

  8. RIDE -- Robot Framework setup

    RobotFramework 是一款基于python 的可以实现关键字驱动和数据驱动并能够生成比较漂亮的测试报告的一款测试框架 这里使用的环境是 python-2.7.10.amd64.msi RID ...

  9. [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 ...

随机推荐

  1. [读书笔记]C#学习笔记八:StringBuilder与String详解及参数传递问题剖析

    前言 上次在公司开会时有同事分享windebug的知识, 拿的是string字符串Concat拼接 然后用while(true){}死循环的Demo来讲解.其中有提及string操作大量字符串效率低下 ...

  2. paip.java swt 乱码问题解决

    paip.java swt 乱码问题解决 看累挂,Dfile.encoding是gbk的.. 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专 ...

  3. paip.java win程序迁移linux的最佳实践

    paip.java win程序迁移linux的最佳实践 1.class load路径的问题... windows哈第一的从calsses目录加载,,而linux优先从jar加载.. 特别的是修理了ja ...

  4. paip.一千 常用汉字 高频汉字 覆盖率90%

    paip.一千 常用汉字 高频汉字 覆盖率90%  一千个使用频率最高的汉字,其覆盖率达一般书刊用字的90%. 作者Attilax  艾龙,  EMAIL:1466519819@qq.com 来源:a ...

  5. Docker + Consul 多数据中心模拟

    Docker + Consul 多数据中心模拟 1. dc1搭建 docker run -d --name node1 -h node1 progrium/consul -server -bootst ...

  6. Android Application 对象介绍

    What is Application Application和Actovotu,Service一样是android框架的一个系统组件,当android程序启动时系统会创建一个 application ...

  7. JavaScript 语句 if else

    顺序.分支和循环语句 if(判断条件) {    满足条件要执行的语句 } else {    不满足条件时执行的语句 } 格式一:if(){} 表示如果括号内的值是true,那就执行花括号中的内容, ...

  8. Java thread jargon

    In Java thread topic, the task to be executed and the thread to drive the task are two concepts shou ...

  9. 日常开发中常见的HTTP协议的状态码

    301Moved Permanently请求的网页已永久移动到新位置.服务器返回此响应(对 GET 或 HEAD 请求的响应)时,会自动将申请人转到新位置.您应使用此代码告诉 Googlebot 某个 ...

  10. 3D touch 静态、动态设置及进入APP的跳转方式

    申明Quick Action有两种方式:静态和动态 静态是在info.plist文件中申明,动态则是在代码中注册,系统支持两者同时存在. -系统限制每个app最多显示4个快捷图标,包括静态和动态 静态 ...