zoukankan      html  css  js  c++  java
  • 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 ("
    ")
    #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;
    }
  • 相关阅读:
    JS_判断浏览器.
    JQ_使用AJAX获取SINA股票代码
    Struts2中的OGNL详解
    CSS原理与CSS经验分享
    Struts 与 Velocity 的集成
    30条HTML代码编写指南 for入门者
    OGNL使用小结
    Visual C++ 6.0 插件系列介绍
    C语言编译过程总结详解
    Web.xml配置详解
  • 原文地址:https://www.cnblogs.com/max88888888/p/7353316.html
Copyright © 2011-2022 走看看