uva 1422 - Processor(二分+优先队列)
来源:互联网 发布:淘宝达人怎么直播 编辑:程序博客网 时间:2024/05/01 23:35
题目链接:uva 1422 - Processor
题目大意:有一个机器要处理一些问题,给出这些问题可以开始的时间和必须完成的时间,以及任务的工作量,问说机器必须以最少每秒多少得工作量才能完成这些任务。
解题思路:二分答案,答案的上限是MaxWork * MaxN(全在一秒内完成)。然后就是判断说在c的工作量小是否能完成任务。因为处理一个问题的时间可以不连续,所以给解题增加了难度。
现将任务按照开始的时间从小到大排序,然后枚举时间区间。开始时间比当前枚举时间小的话入队。
队列用优先队列,结束时间较小的优先满足。
当队列中的第一个元素的结束时间小于当前枚举时间的起始值时,返回false,因为不会再有时间片可以用于解决该问题。
#include <stdio.h>#include <string.h>#include <queue>#include <algorithm>using namespace std;const int N = 10005;struct state {int x, y, w, d;state() { d = 0; }friend bool operator < (state a, state b) {return a.y > b.y;}}s[N];int n, l, r;bool cmp(const state& a, const state& b) {return a.x < b.x;}void init() {l = 0; r = 10000000;scanf("%d", &n);for (int i = 0; i < n; i++)scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].w);sort(s, s + n, cmp);}bool judge(int c) {priority_queue<state> q;int cnt = 0, t = 0;state k;for (int i = 1; i <= 20000; i++) {if ( !q.empty()) {k = q.top();if (k.y + 1 <= i) return false;}while (t < n) {if (s[t].x < i) {q.push(s[t]);t++;} else break;}int cur = c;while (cur && !q.empty()) {k = q.top(); q.pop();int now = min(cur, k.w - k.d);k.d += now; cur -= now;if (k.w - k.d) {q.push(k);} else {cnt++;}}if (cnt == n) return true;}return false;}int solve() {while (true) {if (r - l == 1) break;int mid = (l + r) / 2;if (judge(mid)) r = mid;else l = mid;}return r;}int main () {int cas;scanf("%d", &cas);while (cas--) {init();printf("%d\n", solve());}return 0;}
5 0
- uva 1422 - Processor(二分+优先队列)
- UVA 1422 - Processor (二分+贪心+优先队列)
- UVA 1422 - Processor (二分+贪心+优先队列)
- UVA 1422 Processor(优先队列+贪心+二分)
- UVa 1422 - Processor(二分 + 贪心 + 优先队列)
- UVA 1422 Processor(二分极大值极小化+优先队列)
- UVA 1422 - Processor(二分+优先队列+贪心)
- (intermediate) UVA 贪心+二分+优先队列 1422Processor
- uva1422 - Processor 二分+优先队列
- Processor(二分搜索,优先队列)
- UVA-1422(贪心+二分+优先队列)
- LA 4254 Processor(二分+贪心+优先队列)
- UVALive - 4254 Processor 二分+优先队列
- UVa 1422 Processor 解题报告(二分)
- LA 4254 Processor (单调队列 + 二分)
- UVA1422-Processor(二分法+优先队列)
- UvaLive 4254 Processor 优先队列
- UVA 1422 (LA 4254)- Processor
- 项目进阶 之 持续构建环境搭建(二)Nexus私服器
- Spark各部分功能
- java——reference类型和Primitive类型
- Populating Next Right Pointers in Each Node II
- Element属性方法的浏览器兼容性概览
- uva 1422 - Processor(二分+优先队列)
- MYGUI3.2改造——与HGE结合,实现资源打包
- Android之TextView使用
- Lync 2010 部署过程中碰到的问题
- Java开发中常见的危险信号(中)
- 设计模式(1) - Factory工厂模式
- 请支持我的朋友们为我投上一票
- 随感
- mysql 分库分表