日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Ciel and Robot CodeForces - 322C

發布時間:2023/12/15 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ciel and Robot CodeForces - 322C 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。