首页 > 其他分享 >Codeforces Round #190 (Div. 2)-C. Ciel and Robot

Codeforces Round #190 (Div. 2)-C. Ciel and Robot

时间:2023-06-12 17:31:58浏览次数:38  
标签:return Ciel int ll 190 Codeforces k2 k1 &&


原题链接


C. Ciel and Robot



time limit per test



memory limit per test



input



output


s. Each character of s

  • U': go up, (x, y)  → 
  • D': go down, (x, y)  → 
  • L': go left, (x, y)  → 
  • R': go right, (x, y)  → 

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



a and b, (9 ≤ a, b ≤ 109). The second line contains a string s (1 ≤ |s| ≤ 100, s only contains characters 'U', 'D', 'L', 'R') — the command.


Output



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


把robot沿着s串走一次称为一周期,一周期后走到(x, y)若x != 0 || y != 0则接下来每一周期结束后走到的点都在(0, 0)->(x, y)这条射线上.把(a, b)沿着s串逆方向走,观察是否在这条射线上


#include <bits/stdc++.h>
#define maxn 105
using namespace std;
typedef long long ll;

char s[maxn];
int a, b, x, y, p1, p2;
bool judge(int k1, int k2){
	
	if(k1 == 0 && k2 == 0)
	 return true;
	if(x == 0 && y == 0){
		if(k1 == 0 && k2 == 0)
		 return true;
		return false;
	}
	if(x == 0){
		if(k1 == 0 && (ll)y * k2 > 0 && k2 % y == 0)
		   return true;
		return false;
	}
	if(y == 0){
		if(k2 == 0 && (ll)x * k1 > 0 && k1 % x == 0)
		   return true;
		return false;
	}
	if((ll)x * k2 == (ll)y * k1 && (ll)x * k1 > 0 && (ll)y * k2 > 0 && k1 % x == 0 && k2 % y == 0)
	 return true;
	return false;
}
int main(){
	
//	freopen("in.txt", "r", stdin);
	scanf("%d%d%s", &a, &b, s);
	x = 0;
	y = 0;
	for(int i = 0; s[i]; i++){
	    if(s[i] == 'L')
	     x--;
	    else if(s[i] == 'R')
	     x++;
	    else if(s[i] == 'D')
	     y--;
	    else
	     y++;
	}
	if(judge(a, b)){
		puts("Yes");
		return 0;
	}
	int len = strlen(s);
	for(int i = len-1; i >= 0; i--){
		p1 = a, p2 = b;
		for(int j = i; j >= 0; j--){
			if(s[j] == 'L')
	          p1++;
	    	else if(s[j] == 'R')
	     	  p1--;
	    	else if(s[j] == 'D')
	     	  p2++;
	        else
	          p2--;
		}
		if(judge(p1, p2)){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}





标签:return,Ciel,int,ll,190,Codeforces,k2,k1,&&
From: https://blog.51cto.com/u_16158872/6464287

相关文章

  • Codeforces Round #362 (Div. 2)-D. Puzzles
    原题链接D.PuzzlestimelimitpertestmemorylimitpertestinputoutputBarneylivesincountryUSC(UnitedStatesofCharzeh).USChas n citiesnumberedfrom 1 through......
  • Codeforces Beta Round #29 (Div. 2, Codeforces format)-D. Ant on the Tree
    原题链接D.AntontheTreetimelimitpertestmemorylimitpertestinputoutputConnectedundirectedgraphwithoutcyclesiscalledatree.Treesisaclassofgraphswhic......
  • CodeForces 4B Before an Exam(DP)
    思路:令dp[i][j]为做了i天用了j时间,然后随便转移一下就可以了#include<cstdio>#include<queue>#include<cstring>#include<iostream>#include<cstdlib>#include<algorithm>#include<vector>#include<map>#include<string>#......
  • CodeForces 4D Mysterious Present(DP)
    题意:你有一张长宽为x,y的卡片同时有n个盒子,长宽分别为xi,yi。然后问你卡片最多塞多少层盒子并且把这些盒子按照从里到外输出。思路:由于数据给小了,所以n^2的DP也是可以水过的~#include<iostream>#include<cstdio>usingnamespacestd;constintmaxn=5005;intx[maxn],y[maxn]......
  • CodeForces 645A Amity Assessment
    题意:给你一个2X2的华容道你,问能不能通过初始给出的棋盘然后变换到最后的棋盘思路:由于是一个2X2的...所以怎么做都可以..留意到每个棋子的移动其实都是顺时针或者逆时针的就好做了。#include<cstdio>#include<queue>#include<cstring>#include<iostream>#include<cstdlib>......
  • [转]POI 解析excel报错 java.lang.NoClassDefFoundError: org/apache/poi/ss/usermode
    前几天做了一个excel上传导入功能,为了通用想同步支持xls和xlsx格式。代码编写期并没有报错,所需要的类也都有。可是应用启动完测式功能的时候报了这么一个错Causedby:java.lang.NoClassDefFoundError:org/apache/poi/ss/usermodel/Date1904Support这是为什么呢?我第一感觉是jar......
  • Codeforces Round 877 (Div. 2)
    Preface补题这场补题的时候直接成腐乳了,A题挂两发,B题挂两发,C题挂一发是真的抽象虽然D是个套路题看一眼就秒了,但如果真的比赛时候打真要罚时爆炸了的说后面的EF还是做不来啊岂可修,不过都很有启发性让人感觉神清气爽,不像傻逼蓝桥杯花钱买罪受A.BlackboardList刚开始想错方......
  • Codeforces Round 876 Div2 A-D题解
    CodeforcesRound876Div2A-D题解A.TheGoodArray这个题就是问你对于\(i\leqn\),要求前面后面至少\(ceil(\frac{i}{k})\)个1那我们就贪心的每k个放一个1,或者直接用数学算一下就好了AC代码#include<bits/stdc++.h>usingnamespacestd;constexprintlimit=(......
  • 物理备库在open数据库时报错ORA-01190
    问题描述:物理备库在open数据库时报错ORA-01190,如下所示:数据库:oracle11.2.0.41、异常重现SYS@orcldg>alterdatabaseopen;alterdatabaseopen*ERRORatline1:ORA-10458:standbydatabaserequiresrecoveryORA-01190:controlfileordatafile1isfrombeforeth......
  • [Codeforces Round 876 (Div. 2)][Codeforces 1839D. Ball Sorting]
    题目链接:D-BallSorting题目大意:需要对一个排列按照指定操作进行排序。操作一:在数字间插入一个特殊点,可执行不超过\(k\)次;操作二:将在特殊点旁的数移动到任意位置。所有操作结束后特殊点会消失,要求对所有\(k\in[1,n]\),求出操作二的最少操作次数。分析题意可以得出,操作一放......