Codeforces Round #428 (Div. 2) B. Game of the Rows
来源:互联网 发布:个人手机记工软件 编辑:程序博客网 时间:2024/05/22 23:28
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int MAXN = 1e4+7;const int inf = 1e9;int n,k;int num[MAXN]; int main(){cin>>n>>k;int x,i;priority_queue<int>q;for(i=0;i<k;i++){cin>>x;q.push(x);}//x1表示四连坐,x2表示2连坐,x3表示 四连坐还能坐一个的int x1=n,x2=n*2,x3=0;//定义初始状态while(!q.empty())//当队列不为空时 {x=q.top();q.pop();if(x>=4)//若元素 x 大于等于4 {int d = x/4;//定义d为用去4连坐个数 if(x1>d)//若四连坐足够 {x1-=d;//x1减去用去的剩下的为x1 if(x%4)//若X除以4有余数 q.push(x%4);//将余数放入队列中 }else{x-=x1*4;//x减去已有四连坐个数剩下的为x; x1=0;//此时已无可用的四连坐 x2-=(x+1)/2;//x2减去剩下的(x+1)*2为x2; }}//此时x>=4的情况已经列举完毕; else if(x==3)//当x=3的时候,{if(x1)//若还有空的四连坐 x1--;//空的四连坐 减 1; else x2-=2;//若没有空的四连坐,,二连坐减 2; } else if(x==2) //若元素 x 等于2 {if(x1)//若还有空的四连坐 x1-- , x3++; //空的四连坐 减 1;四连坐还能坐一个的加 1;else if(x2)//若还有空的二连坐 x2--;//空的二连坐减 1 else //若此时没有空的二连坐和空的四连坐 x3-=2;//此时四连坐还能坐一个的减 2 ; } else//若元素 x 等于1 {if(x3)//若还有四连坐还能坐一个的x3--; //四连坐还能坐一个的减 1 ; else if(x2)//若还有空的二连座 x2--;//空的二连坐的个数减 1 ;else //若没有空的二连坐且没有四连坐还有一个的 x1--, x2++;//空的四连坐 减 1,空的二连坐加 1. } if(x1<0||x2<0||x3<0)return 0*puts("NO"); } puts("YES");return 0;}
阅读全文
0 0
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) Game of the Rows (思维)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) 839B. Game of the Rows(思维+贪心)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- Codeforces Round #428 (Div. 2) B. Game of the Rows (思维)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心,补题)
- CF —— Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2)-贪心&模拟-B. Game of the Rows
- codeforces #428 Div.2 B. Game of the Rows 贪心、思维
- Codeforces 428(div 2)B. Game of the Rows(思维题)
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- codeforces 839A 428 Div2 B Game of the Rows
- Game of the Rows CodeForces
- Game of the Rows CodeForces
- 安卓SQLite
- codeforces406D LCA+凸包
- 学习MarkDown编辑器。不看会后悔
- Python中bool类型转换
- HDU-1018- Big Number
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- docker常用命令
- java带返回值的线程示例,简单方便
- kafka 数据可靠性深度解读
- 面向对象的23种设计模式
- [日推荐] 『美女hold住』你要的美女图,这都有,你懂的 !
- 在Ubuntu16.04中安装MySQL
- JDBC学习
- 重写(Overriding)与重载(Overloading)的区别