codeforces 911C (找規律)

題目描述

Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.

When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.

Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.

Help Mishka by telling him if it is possible to do this!

思路

通過找規律發現,只有一下幾種情況時才成立

1 X X
2 2 X
3 3 3
4 4 2

直接判斷即可

代碼

#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long LL;
const int N=5005;
const int M=150;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
int cnt[N];
void solve(){
    int k1,k2,k3;cin>>k1>>k2>>k3;
    cnt[k1]++;
    cnt[k2]++;
    cnt[k3]++;
    if(cnt[1]>=1) cout<<"YES"<<endl;
    else if(cnt[2]>=2) cout<<"YES"<<endl;
    else if(cnt[3]>=3) cout<<"YES"<<endl;
    else if(cnt[4]==2 && cnt[2]==1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
int main(){
    IOS;
    solve();
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章