codeforces C. Infinite Fence

C. Infinite Fence
Educational Codeforces Round 77 (Rated for Div. 2)

You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.

You must paint a fence which consists of 10100 planks in two colors in the following way (suppose planks are numbered from left to right from 0):

if the index of the plank is divisible by r (such planks have indices 0, r, 2r and so on) then you must paint it red;
if the index of the plank is divisible by b (such planks have indices 0, b, 2b and so on) then you must paint it blue;
if the index is divisible both by r and b you can choose the color to paint the plank;
otherwise, you don’t need to paint the plank at all (and it is forbidden to spent paint on it).
Furthermore, the Government added one additional restriction to make your punishment worse. Let’s list all painted planks of the fence in ascending order: if there are k consecutive planks with the same color in this list, then the Government will state that you failed the labor and execute you immediately. If you don’t paint the fence according to the four aforementioned conditions, you will also be executed.

The question is: will you be able to accomplish the labor (the time is not important) or the execution is unavoidable and you need to escape at all costs.

Input

The first line contains single integer T (1≤T≤1000) — the number of test cases.

The next T lines contain descriptions of test cases — one per line. Each test case contains three integers r, b, k (1≤r,b≤109, 2≤k≤109) — the corresponding coefficients.

Output

Print T words — one per line. For each test case print REBEL (case insensitive) if the execution is unavoidable or OBEY (case insensitive) otherwise.
Example

4
1 1 2
2 10 4
5 2 3
3 2 2

output

OBEY
REBEL
OBEY
OBEY

题意:
现有10100块木板需要涂漆,第x块如果是x是r的倍数,则涂一种颜色,是b的倍数,则涂另一种颜色。如果既是r又是b的倍数,那么两种颜色都可以涂;如果连续有k块板的颜色是一样的,则输出REBEL,否则输出OBEY。问是否能避免被处死

题解:

假设r<b
因为在编号为 | (k-1)b,x1r , x2r , …,… ,xnr, kb | 的区间中 (k-1)B与x1M的距离并不是r,当编号不断增大时它们的距离是会变的最短距离为gcd(B,M), 故我们只需在剩下的区间判断是否有k-1个M就行了

很多人包括我想法是没错的,就是首距离错误的理解为就是r,就是只考虑首个区间,并没有考虑第二个,第三个甚至很多很多个
| (k-1)b,x1r , x2r , …,… ,xnr, kb | 的区间。其实就是我cai

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	int r,b,k;
	scanf("%d",&n);
	//标号从0开始!
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&r,&b,&k);
		int B=max(r,b);//大 
		int M=min(r,b);//小 
		int z=0;
		int len=__gcd(r,b); 
		//if(B%M==0)
		//z=1;
		//不用判断   不管 B是max(r,b)最大者的倍数还是公共的倍数都为B的颜色 
		if(r==b)
		printf("OBEY\n");//ok
		//else if((B/M-z)>=k) //错误 
		//因为区间 | (k-1)B- x1M - x2M - …… - kB | 中 (k-1)B与x1M的距离并不是r,
		//它们的距离是会变的,最短为gcd(B,M) 故我们只需在剩下的区间判断是否有k-1个M就行了 
		else if((B-1-len)/M>=k-1)
		printf("REBEL\n");
		else
		printf("OBEY\n");
	}
	return 0;
}

其实B和M就是r和b中,较大和较小的值,一个判断加swap()就行了,没必要写那些乱七八糟的东东~

发布了68 篇原创文章 · 获赞 15 · 访问量 9013

猜你喜欢

转载自blog.csdn.net/qq_43791377/article/details/103319211