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

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

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[n]==0) continue;
		if (t2!=0&&y[n]==0) continue;
		if (x[n]==0||y[n]==0)
		{
			bool bo1=0,bo2=0;
			if (x[n]==0) bo1=1;
			if (y[n]==0) bo2=1;
			if (bo1&&!bo2) if (t2%y[n]==0&&t2/y[n]>=0) {cout<<"Yes"<<endl;return 0;} else continue; 
			if (!bo1&&bo2) if (t1%x[n]==0&&t1/x[n]>=0) {cout<<"Yes"<<endl;return 0;} else continue;
			if (!x[i]&&!y[i]) {cout<<"Yes"<<endl;return 0;} else continue;
		}
		if (t1%x[n]||t2%y[n]) continue;
		t1/=x[n],t2/=y[n];
		if (t1<0||t2<0||t1^t2) continue;
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	
	return 0;
}







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值