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

题目:https://codeforces.com/contest/1260/problem/C
思路:裴蜀定理:\(a*x+b*y=c\)  仅当 \(gcd(a,b)\mid{c}\) 时,等式成立
\(b>r\)
\(y*b\) 被染为蓝色,最近的 \(x*r\)\(y*b\) 的距离 \(c_{min}=gcd(b,r)\)
根据题意:\(x*r+(k-1)*r\ge y*b+b\longrightarrow y*b+gcd(b,r)+(k-1)*r\ge y*b+b\)
所以 \(gcd(b,r)+(k-1)*r-b\ge 0\)

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;
    while(T--)
    {
        ll r,b,k;
        cin>>r>>b>>k;
        if(r>b) swap(r,b);
        if(gcd(b,r)+(k-1)*r>=b) cout<<"OBEY"<<endl;
        else cout<<"REBEL"<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/c4Lnn/p/12104519.html