CF —— Codeforces Round #428 (Div. 2) B. Game of the Rows

来源:互联网 发布:sql case when null 编辑:程序博客网 时间:2024/06/03 17:46

题目:

B. Game of the Rows

题解:

1.先将人分为4,3,2,1;将4,3填入中间4连座,然后将2填入两旁2连座,统计剩余座位和2,1的人
2.若2连座有剩余,则只需将超出4连座的4,3以及1尝试填入2;
3.若2连座不足,则将2,1填入4连座,最好为1个四连座填一个1和一个2.
4,若能填完所有人则为YES,否则为NO。

AC代码:

#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <string>#include <cstring>#define maxn 100000 + 10#define   For(a,b)  for(int i = a; i < b; i++)typedef long long LL;int n,k;using namespace std;int main(){    cin >> n >> k;    int t;    int j = 0;    int x=0,y=0,z=0;    for(int i = 0; i < k; i++)    {        scanf("%d",&t);                x += t/4;        if(t%4 == 1) y++;                if(t%4 == 3) x++;        if(t%4 == 2) z++;    }           int nn = n - x;           int nm = n*2 - z;      //      cout << nn <<" "<< nm<< " " << x << " "<< y << " "<< z << endl;      if(nm < 0)    {        if(nm+y>0)               if((nn-min(nm*(-1),y))*2 >= y+nm)                   printf("YES\n");                    else  printf("NO\n");           else if(nm+y < 0)                   if((nn-min(nm*(-1),y))*3 >= (y+nm)*(-1)*2)             printf("YES\n");                  else    printf("NO\n");          else  {                if(nn-y >= 0)               printf("YES\n");                else printf("NO\n");             }      }    else if(nn *2 + nm >= y) printf("YES\n");    else printf("NO\n");    return 0;}
原创粉丝点击