您的位置:首页 > 其它

CF 321A(Ciel and Robot-暴力枚举)

2013-06-29 17:13 441 查看
A. 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 strings. 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.

Sample test(s)

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

大致思路:

机器人必然走n个循环+1段

所以只要暴力枚举段

设到第i步时机器人在(xi,yi)

则xt=t*xn+xi yt=t*yn+yi

乱搞即可……

过了Present Test(好激动!数回Div2 只做2题的菜)

结果Final Wa 了……

//我是白痴……

经鉴定,是我68行把||打成了&&……

我的Div 1 啊!!!!!!!!


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (50000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
ll a,b;
int n;
char s[1000];
int x[1000],y[1000];
int main()
{
//	freopen("robot.in","r",stdin);
//	freopen(".out","w",stdout);
cin>>a>>b;
scanf("%s",s+1);n=strlen(s+1);
x[0]=y[0]=0;
bool bo=0;
For(i,n)
{
if (s[i]=='R') x[i]=x[i-1]+1,y[i]=y[i-1];
if (s[i]=='L') x[i]=x[i-1]-1,y[i]=y[i-1];
if (s[i]=='U') x[i]=x[i-1],y[i]=y[i-1]+1;
if (s[i]=='D') x[i]=x[i-1],y[i]=y[i-1]-1;
if (x[i]==a&&y[i]==b) bo=1;
}
if (bo==1)
{
cout<<"Yes"<<endl;
return 0;
}
Rep(i,n+1)
{
int t1=a-x[i],t2=b-y[i];
if (t1!=0&&x
==0) continue;
if (t2!=0&&y
==0) continue;
if (x
==0||y
==0)
{
bool bo1=0,bo2=0;
if (x
==0) bo1=1;
if (y
==0) bo2=1;
if (bo1&&!bo2) if (t2%y
==0&&t2/y
>=0) {cout<<"Yes"<<endl;return 0;} else continue;
if (!bo1&&bo2) if (t1%x
==0&&t1/x
>=0) {cout<<"Yes"<<endl;return 0;} else continue;
if (!x[i]&&!y[i]) {cout<<"Yes"<<endl;return 0;} else continue;
}
if (t1%x
||t2%y
) continue;
t1/=x
,t2/=y
;
if (t1<0||t2<0||t1^t2) continue;
cout<<"Yes"<<endl;
return 0;
}
cout<<"No"<<endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: