zoukankan      html  css  js  c++  java
  • 839B

    839B - Game of the Rows

    题意:

    题解:

    贪心~

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int have[5],cnt[3];
     4 
     5 int main(){
     6     int n,k;
     7     scanf("%d%d",&n,&k);
     8     have[4]=n;have[2]=n+n;
     9     int flag=1;
    10     int x;
    11     for(int i=0;i<k;i++){
    12         scanf("%d",&x);
    13         while(x>=3){
    14             if(have[4]>0){
    15                 have[4]--;
    16                 x-=4;
    17             }else if(have[2]>0){
    18                 have[2]--;
    19                 x-=2;
    20             }else {
    21                 flag=0;
    22             }
    23         }
    24         if(x>0) cnt[x]++;
    25     }
    26     while(cnt[2]>0){
    27         if(have[2]>0){
    28             have[2]--;
    29             cnt[2]--;
    30         }else if(have[4]>0){
    31             cnt[2]--;
    32             have[4]--;
    33             have[1]++;
    34         }else {
    35             cnt[2]--;
    36             cnt[1]+=2;
    37         }
    38     }
    39     if(cnt[1]>have[1]+have[2]+have[4]*2) flag=0;
    40     if(flag) puts("YES");
    41     else puts("NO");
    42 }
    View Code
  • 相关阅读:
    API
    API
    for in
    event flow
    object
    Report of program history
    正则表达式
    伪类与伪元素
    Position
    js学习之原型(补充)
  • 原文地址:https://www.cnblogs.com/yijiull/p/7363340.html
Copyright © 2011-2022 走看看