839B - Game of the Rows

 

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

 

posted @ 2017-08-15 09:23  yijiull  阅读(202)  评论(0编辑  收藏  举报