Codeforces Round #428 B

Game of the Rows

题意:如图,{1, 2}, {3, 4}, {4, 5}, {5, 6} , {7, 8}的位置是相邻的,n排位置,给k组人,每组ai个人,不同组的人不能相邻,如果可能输出YES否则输出NO

思路:分成1人,2人,4人的来安排座位,能分成4人尽量先分成4人,然后先安排4人再安排2人的再安排1人的,xjbif

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define ll long long
#define endl ("\n")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const long long INF = 1e18+1LL;
const int inf = 1e9+1e8;
const int N=1e5+100;
const ll mod=1e9+7;

int f,t,m,n,k;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for(int i=1; i<=k; ++i){
        int x; cin>>x;
        m+=x/4;
        if(x%4==1) f++;
        if(x%4==2) t++;
        if(x%4==3) f++,t++;
    }
    int z=n,b=2*n;
    if(m<=n){
        z-=m;
        if(t<=b){
            b-=t;
            if(f<=z*2+b){
                cout<<"YES";
            }
            else cout<<"NO";
        }
        else{
            t-=b;
            if(t<=z){
                z-=t;
                f-=t;
                if(f<=z*2){
                    cout<<"YES";
                }
                else cout<<"NO";
            }
            else{
                f-=z;
                t-=z;
                f+=t*2;
                if(f<=0){
                    cout<<"YES";
                }
                else cout<<"NO";
            }
        }
    }
    else{
        m-=n;
        m*=2;
        t+=m;
        if(t+f<=b){
            cout<<"YES";
        }
        else cout<<"NO";
    }
    return 0;
}

 

posted on 2017-08-13 13:59  lazzzy  阅读(148)  评论(0编辑  收藏  举报

导航