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.

Examples
Input
2 2
RU
Output
Yes
Input
1 2
RU
Output
No
Input
-1 1000000000
LRRLU
Output
Yes
Input
0 0
D
Output
Yes
Note
In the first and second test case, command string is “RU”, so the robot will go right, then go up, then right, and then up and so on.

The locations of its moves are (0, 0)  →  (1, 0)  →  (1, 1)  →  (2, 1)  →  (2, 2)  →  …

So it can reach (2, 2) but not (1, 2).
可以无限次的重复给出的过程,问可不可以达到目标点。想想都不可能是直接暴力的模拟。肯定有巧妙地方法。我们仔细想想,走到每一步的时候,在经过好几个轮回都有可能到达目标点。所以我们需要记录走每一步的时候坐标改变的程度,以及走完一个轮回坐标改变的程度。然后在遍历一遍就可以了。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;const int maxx=101;
char s[maxx];
int x,y;
int a[maxx];
int b[maxx];int main()
{while(scanf("%d%d",&x,&y)!=EOF){int xx=0,yy=0;getchar();gets(s);if(xx==x&&yy==y) {cout<<"Yes"<<endl;continue;}int flag=0;int len=strlen(s);for(int i=0;i<len;i++){if(s[i]=='U') yy++;if(s[i]=='D') yy--;if(s[i]=='R') xx++;if(s[i]=='L') xx--;a[i]=xx;b[i]=yy;}int k; for(int i=0;i<len;i++){if(xx){k=(x-a[i])/xx;}else if(yy){k=(y-b[i])/yy;}if(k<0) k=0;if(x==k*xx+a[i]&&y==k*yy+b[i]){flag=1;break;}}if(flag) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
}

努力加油a啊,(o)/~

Ciel and Robot CodeForces - 322C相关推荐

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

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

  2. Yet Another Walking Robot CodeForces - 1296C

    There is a robot on a coordinate plane. Initially, the robot is located at the point (0,0)(0,0). Its ...

  3. android studio生命周期代码,Android Studio 单刷《第一行代码》系列 06 —— Fragment 生命周期...

    前情提要(Previously) 本系列将使用 Android Studio 将<第一行代码>(书中讲解案例使用Eclipse)刷一遍,旨在为想入坑 Android 开发,并选择 Andr ...

  4. CodeForces 1463 C. Busy Robot 模拟

    CodeForces 1463 C. Busy Robot 模拟 题目大意: 有一个一维坐标轴,在最初时刻有个机器人位于坐标 0 0 0 位置,有 n n n 个命令,对于每一个命令在 t i t_i ...

  5. 【codeforces 752C】Santa Claus and Robot

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. Codeforces 1196C Robot Breakout

    https://codeforces.com/contest/1196/problem/C 题解:思维+交集 /* *@Author: STZG *@Language: C++ */ #include ...

  7. Codeforces Round #753 (Div. 3)E. Robot on the Board 1

    问题翻译: The robot is located on a checkered rectangular(直角 的) board of size n×m (n rows, m columns). T ...

  8. Codeforces Round #190 (Div. 1): E. Ciel and Gondolas(决策单调性DP+wqs二分)

    E. Ciel and Gondolas 题意: bzoj5311:https://www.lydsy.com/JudgeOnline/problem.php?id=5311 同一道题目,但是bzoj ...

  9. Codeforces 583 DIV2 Robot's Task 贪心

    原题链接:http://codeforces.com/problemset/problem/583/B 题意: 就..要打开一个电脑,必须至少先打开其他若干电脑,每次转向有个花费,让你设计一个序列,使 ...

最新文章

  1. Yahoo网站性能优化的34条规则
  2. 动态修改页面Meta 标签 keywords description
  3. 4月24日Serverless Developer Meetup上海亮相
  4. OkHttp实现分析之Websocket
  5. 单例模式讨论篇:单例模式与垃圾回收
  6. 程序员需要了解的十个高级SQL概念
  7. 网络知识普及:双网卡下知识知多少,路由表及网关那点事
  8. 半监督学习的概述与思考,及其在联邦场景下的应用(续)
  9. 安装centos7后不能联网
  10. 哈希表:如何利用好高效率查找的“利器”?
  11. weightad interval scheduling problems
  12. 日历代码(微信小程序)
  13. 内网穿透工具NatApp使用教程
  14. 中国企业培训的十大缺陷(zt)
  15. Linux搭建部署JDK1.7环境
  16. 程序员书籍PDF大收集
  17. snmp v3 参数_SNMP V3的配置指南
  18. Oracle 常见错误总结及问题解决方法
  19. 说说这三四年我用过的语音IC架构
  20. java饲养员喂动物_体现JAVA中的面向对象思想,接口(抽象类)的用处 :饲养员给动物喂食物...

热门文章

  1. IOS基础使用PCH文件全局定义宏常量
  2. 整数划分问题的递归算法-c语言,简单的整数划分问题(递归)
  3. k8s里面的项目怎么暴露端口让用户访问_从零开始入门 K8s | 可观测性:监控与日志...
  4. 不连续曲线 highcharts_无人车运动规划中常用的方法:多项式曲线
  5. kafka maven没有下载_构建工具的进化:ant, maven, gradle
  6. Android开发之自定义view绘制坐标位置出错的问题解决
  7. Android开发之解决ListView和ScrollView滑动冲突的方法
  8. 2013年 省职业学校 公共基础课程 两课 评比 计算机应用,江苏省职业学校公共基础课程两课评比教案.doc...
  9. android纵向列表菜单栏实现,RecyclerView实现常见的列表菜单
  10. 想问一下C++里queue要怎么遍历