codeforces 911C (找规律)

时间:2022-07-28
本文章向大家介绍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;
}