codeforces A. Ciel and Robot

本文探讨了一个关于机器人在二维平面上遵循指令移动并判断是否能到达指定坐标点的问题。通过解析输入字符串指令,模拟机器人移动过程,并判断最终位置是否与目标坐标匹配。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
这道题的思路很简单,大家都可以想到,但是我写的程序bug太多了,昨晚没调出来,今天在测试数据下还调了几乎一上午,不得不说自己考虑什么真的很不全面,其实都是对除0,以及正负号的,自己的思路很不严密啊,下面贴出修改了n次的代码,o(╯□╰)o!
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define repf(i,n,m) for(int i=(n); i<=(m); ++i)
#define repd(i,n,m) for(int i=(n); i>=(m); --i)
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define fab(a) ((a)>0?(a):(0-(a)))
#define ll long long
#define arc(a) ((a)*(a))
#define inf 100000
#define exp 0.000001
#define N 200
char s[N];
ll x,y;
struct node{
	ll x,y;
}a[N];
int main()
{ 
	int sign=0;
   while(cin>>x>>y)
	{
		sign++; 
		cin>>s;
        a[0].x=a[0].y=0;
		int len=strlen(s);
		int flag=0;
        rep(i,len)
		{
			a[i+1].x=a[i].x;a[i+1].y=a[i].y;
           if(s[i]=='U')  a[i+1].y++;
		   if(s[i]=='D')  a[i+1].y--;
		   if(s[i]=='L')  a[i+1].x--;
		   if(s[i]=='R')  a[i+1].x++;
		   if(a[i+1].x==x && a[i+1].y==y)
			   flag=1;
		} 
		if(x==0 && y==0)
		{printf("Yes\n"); continue;}
		ll xx=a[len].x,yy=a[len].y;
		if((xx==0 && yy==0)&& flag==0)
		{printf("No\n");continue;}  
        if(flag==0)
        { 
		  rep(i,len+1)
		  {  
             if(xx==0 && yy!=0 && (y-a[i].y)%yy==0&& a[i].x==x)
               flag=1;
             if(yy==0 && xx!=0 &&(x-a[i].x)%xx==0 && y==a[i].y)
              flag=1;
             if(xx*yy!=0 && (x-a[i].x)%xx==0 &&(y-a[i].y)%yy==0)
              flag=1;
             if(flag==1)
             {   
                 if(xx*yy!=0 && (x-a[i].x)/xx!=(y-a[i].y)/yy)
                  flag=0;
                 if(xx!=0 && (x-a[i].x)*xx<0)
                 flag=0;
                 if(yy!=0 && (y-a[i].y)*yy<0)
                 flag=0;
                 if(flag==1)
                   break;
             }
		  }
        }
		if(flag==1)
			printf("Yes\n");
		else
			printf("No\n");

	 }
   return 0;
}



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

淡定的小Y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值