Codeforces Round #190 (Div. 2)-C. Ciel and Robot
来源:互联网 发布:js点击触发事件 方法名 编辑:程序博客网 时间:2024/05/16 05:16
原题链接
C. Ciel and Robot
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputFox 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 2RU
output
Yes
input
1 2RU
output
No
input
-1 1000000000LRRLU
output
Yes
input
0 0D
output
Yes
#include <bits/stdc++.h>#define maxn 105using namespace std;typedef long long ll;char s[maxn];int a, b, x, y, p1, p2;bool judge(int k1, int k2){if(k1 == 0 && k2 == 0) return true;if(x == 0 && y == 0){if(k1 == 0 && k2 == 0) return true;return false;}if(x == 0){if(k1 == 0 && (ll)y * k2 > 0 && k2 % y == 0) return true;return false;}if(y == 0){if(k2 == 0 && (ll)x * k1 > 0 && k1 % x == 0) return true;return false;}if((ll)x * k2 == (ll)y * k1 && (ll)x * k1 > 0 && (ll)y * k2 > 0 && k1 % x == 0 && k2 % y == 0) return true;return false;}int main(){//freopen("in.txt", "r", stdin);scanf("%d%d%s", &a, &b, s);x = 0;y = 0;for(int i = 0; s[i]; i++){ if(s[i] == 'L') x--; else if(s[i] == 'R') x++; else if(s[i] == 'D') y--; else y++;}if(judge(a, b)){puts("Yes");return 0;}int len = strlen(s);for(int i = len-1; i >= 0; i--){p1 = a, p2 = b;for(int j = i; j >= 0; j--){if(s[j] == 'L') p1++; else if(s[j] == 'R') p1--; else if(s[j] == 'D') p2++; else p2--;}if(judge(p1, p2)){puts("Yes");return 0;}}puts("No");return 0;}
0 0
- Codeforces Round #190 (Div. 2)-C. Ciel and Robot
- Codeforces Round 190 div.2 322C 321A Ciel and Robot
- Codeforces Round #190 (Div. 2)---A. Ciel and Dancing
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- Codeforces Round #206 (Div. 2) C. Vasya and Robot
- Codeforces Round #206 (Div. 2) C-Vasya and Robot
- 想法题——Codeforces Round #190 (Div. 2)——B. Ciel and Flowers
- codeforces A. Ciel and Robot
- Codeforces Round #389(Div.2)C Santa Claus and Robot【思维】
- Codeforces Round #389 (Div. 2) C. Santa Claus and Robot 贪心+最短路
- CodeForces 321A Ciel and Robot[暴力]
- CodeForces 321 A - Ciel and Robot
- CodeForces 321A Ciel and Robot
- Codeforces Round #190 (Div. 2) E. Ciel the Commander 题目与题解翻译
- Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
- Codeforces Round #206 (Div. 1) A. Vasya and Robot
- CodeForces 321A Ciel and Robot(数学模拟)
- Codeforces 321A Ciel and Robot 枚举答案
- ionic开发禁止横屏处理
- OLTP与OLAP的区别分析
- mapper注入失败问题解决 {@org.springframework.beans.factory.annotation.Autowired(required=true)}
- 接口类型的泛型
- C#43课的主要内容
- Codeforces Round #190 (Div. 2)-C. Ciel and Robot
- 第一章 TCP/IP概述
- UVa - 1395 - Slim Span(Kruskal算法+并查集,最小生成树)
- 点云匹配
- C++中类的实例化的两种方法
- Linux进程间的通信方式:信号量的使用
- android 开发中遇到错误及解决办法总结
- 多线程间变量的共享
- 洛谷P2658 汽车拉力比赛