AtCoder Regular Contest 080C: 4-adjacent 題解

思維題
首先所有的數可以分成能被4整除的,能被2整除但不能被4整除的和沒有2因子的三類
顯然如果沒有最後一類的話是顯然可以的,所以我們只要考慮是否每個最後一類的數都能保證其左右都是第一類數
如果沒有第二類數,那麼只要第一類數個數大於等於第三類個數減一就行,因爲最極端的可以出現31313這樣的例子
如果有第二類數,那麼就得保證第一類樹個數大於等於第三類數個數

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const LB eps=1e-10;
const LB pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n;
int a[100048];
int cnt1,cnt2,cnt4;

int main ()
{
    int i;
    n=getint();
    for (i=1;i<=n;i++) a[i]=getint();
    for (i=1;i<=n;i++)
    {
        if (a[i]%4==0) {cnt4++;continue;}
        if (a[i]%2==0) {cnt2++;continue;}
        cnt1++;
    }
    if (cnt2==0)
    {
        if (cnt4>=cnt1-1) cout<<"Yes"<<endl; else cout<<"No"<<endl;
        return 0;
    }
    if (cnt4>=cnt1) cout<<"Yes"<<endl; else cout<<"No"<<endl;
    return 0;
}
發佈了182 篇原創文章 · 獲贊 40 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章