博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ciel and Robot
阅读量:5424 次
发布时间:2019-06-15

本文共 2144 字,大约阅读时间需要 7 分钟。

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| ≤ 100s only contains characters 'U', 'D', 'L', 'R') — the command.

Output

Print "Yes" if the robot will be located at (a, b), and "No" otherwise.

细节蛮多的,做的我好忧伤。。。

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 9 int main()10 {11 char s[101];12 int a, b, dx, dy, i;13 while(scanf("%d %d", &a, &b) != EOF)14 {15 scanf("%s", s);16 dx = dy = 0;17 for(i = 0; s[i] != '\0'; i++)18 {19 if(dx == a && dy == b) break;20 if(s[i] == 'U') dy++;21 else if(s[i] == 'D') dy--;22 else if(s[i] == 'L') dx--;23 else dx++;24 }25 if(s[i] == '\0')26 {27 int dx2 = abs(dx), dy2 = abs(dy);28 for(i = 0; s[i] != '\0'; i++)29 {30 if(s[i] == 'U') b--;31 else if(s[i] == 'D') b++;32 else if(s[i] == 'L') a++;33 else a--;34 if(!a && !b) break;35 int a2 = abs(a), b2 = abs(b);36 if((long long)a * dy == (long long)b * dx && (long long)b * dy >= 0 && (long long)a * dx >= 0)37 {38 if(dy && dx)39 {40 if(a2 % dx2 == 0 && b2 % dy2 == 0) break;41 }42 else if(!dx && dy)43 {44 if(!a && b2 % dy2 == 0) break;45 }46 else if(dx && !dy)47 {48 if(!b && a2 % dx2 == 0) break;49 }50 }51 }52 }53 if(s[i] != '\0') puts("Yes");54 else puts("No");55 }56 return 0;57 }
View Code

转载于:https://www.cnblogs.com/cszlg/p/3242265.html

你可能感兴趣的文章
Browsersyuc 入门
查看>>
git push失败the remote end hung up unexpectedly
查看>>
POJ3087 Shuffle'm Up 简单模拟
查看>>
Django中数据的增删改查
查看>>
iOS模拟器发生了崩溃,去哪找Crash Log
查看>>
[支付宝]即时到账接口对接总结
查看>>
Django框架之图书管理系统(二)
查看>>
夺命雷公狗-----React---15--三元运算符
查看>>
Python 反射
查看>>
元首的愤怒 SharePoint Apps
查看>>
CSS
查看>>
记录我学github的路程(二)
查看>>
两个DataGrid垂直滚动条同步滚动
查看>>
RPG的错排
查看>>
解决checkbox在滑动时选中状态错乱的问题
查看>>
Java 7之基础 - 强引用、弱引用、软引用、虚引用
查看>>
位运算
查看>>
设计模式之原型模式
查看>>
我的面试错题
查看>>
Servlet
查看>>