Codeforces 839B Game of the Rows 贪心
来源:互联网 发布:vba 窗体输入数据回调 编辑:程序博客网 时间:2024/05/22 11:31
传送门:Codeforces 839B
题意:有k个小队坐飞机,每个小队有a[i]人,飞机上有n排座位,每排座位有8个,定义同一排中{1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}. 几个座位是相邻的,问能否保证相邻的座位中没有两个不同的队伍的人。
思路:先贪心的使用3、4、5、6四个座位,然后再用两边的,我是用优先队列维护的这一过程,比赛的时候傻X的一行一行的使用座位,应该是先用所有行中的4个相邻的座位。
代码:
#include<bits/stdc++.h>#define ll long long#define pi acos(-1)#define MAXN 100010#define inf 0x3f3f3f3fusing namespace std;typedef pair<int,int>P;int w[110],que[110];priority_queue<int, vector<int>, less<int> > q;int main(){int n, k;cin >> n >> k;for(int i = 0; i < k; i++)cin >> w[k], q.push(w[k]);int last = 0, tmp;int a, b, kk = 0;for(int i = 0; i < n; i++)// 先塞满4个相邻的{ if(q.empty()) { cout << "YES"; return 0; }a = q.top(); q.pop();if(a >= 4) { a -= 4; if(a) q.push(a); } else { if(a == 2) kk++; if(a == 1 && !q.empty()) q.pop(); }}for(int i = 0; i < n; i++)//再塞满两边两对 { if(q.empty()) { cout << "YES"; return 0; } a = q.top(); q.pop(); if(a > 2) q.push(a - 2); if(!q.empty()) { a = q.top(); q.pop(); if(a > 2) q.push(a - 2); } }if(q.empty())cout << "YES";else{int tmp;while(!q.empty()){kk -= q.top();q.pop();}if(kk >= 0)cout << "YES";elsecout << "NO";} return 0;}
阅读全文
0 0
- Codeforces 839B Game of the Rows (贪心)
- Codeforces 839 B. Game of the Rows (贪心)
- Codeforces 839B Game of the Rows 贪心
- codeforces#839 B Game of the Rows 思维,贪心
- Game of the Rows codeforces 839B(贪心)
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- Codeforces Round #428 (Div. 2) 839B. Game of the Rows(思维+贪心)
- B. Game of the Rows(贪心)
- 839B Game of the Rows(水,思维,贪心)
- Codeforce 839 -- B Game of the Rows 【思维 + 贪心】
- codeforces 839A 428 Div2 B Game of the Rows
- codeforces 839B Game of the Rows(思路题)
- CodeForces-839B Game of the Rows(思维、细节)
- codeforces 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(贪心)
- (ubuntu系列)——备份和还原
- 面向对象的三个基本特征 和 五种设计原则
- Celery消息队列----配置定时任务
- 2017年Android SDK下载安装及配置教程
- Coursera机器学习 Week1 笔记
- Codeforces 839B Game of the Rows 贪心
- java 断言 assert 初步使用:断言开启、断言使用
- Java的Properties文件操作类
- 微信第三方平台开发经验总结(一):接收component_verify_ticket
- UGUI中的Canvas、Camera和Canvas Scaler
- ITTVIS.ENVI.Orthorectification.v5.0.SP2.Win32_64 2CD
- OnTrimMemory使用与举例
- Java多线程中wait()和notify()
- jsp百度编辑器ueditor 提示后端配置项没有正常加载,上传插件不能正常使用!