UVA 1422 Processor(二分极大值极小化+优先队列)
来源:互联网 发布:网络三级分销体系 编辑:程序博客网 时间:2024/05/02 04:40
题意:
给定n个任务,每个任务必须在时间[R,D]内完成,每个任务工作量为W,问最小完成速率使得所有工作完成。
思路:
二分求下界的问题,判断的时候利用优先队列,由于时间只有20000,去枚举每个单位时间,看要给分配个那个任务,这步利用优先队列,按d越小越先出队,因为d越小肯定要越快完成越好。
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <cstdlib>using namespace std;typedef long long ll;const int N = 10005;int n;struct Process { int r, d, w; friend bool operator < (Process a, Process b) { return a.d > b.d; }}pro[N];bool cmp(Process a, Process b) { return a.r < b.r;}void init() { scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d%d%d", &pro[i].r, &pro[i].d, &pro[i].w); } sort(pro, pro+n, cmp);}bool judge(int M) { priority_queue<Process> que; int idx = 0; for(int i = 1; i <= 20000; i++) { while(idx < n && pro[idx].r < i) que.push(pro[idx++]); int speed = M; while(speed > 0 && !que.empty()) { Process front = que.top(); que.pop(); if(front.d < i) return false; if(front.w > speed) { front.w -= speed; speed = 0; que.push(front); }else { speed -= front.w; } } if(que.empty() && idx == n) return true; } return false;}int calc() { int L = 1, R = 100000; while(L < R) { int M = (L+R)/2; if(judge(M)) R = M; else L = M+1; } return L;}int main() { int T; scanf("%d", &T); while(T--) { init(); printf("%d\n", calc()); } return 0;}
0 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 解题报告(二分)
- UVA 11627 Slalom(二分极小值极大化)
- LA 4254 Processor (单调队列 + 二分)
- UVA1422-Processor(二分法+优先队列)
- UvaLive 4254 Processor 优先队列
- ios开发之自定义默认生成的导航栏 标题 颜色 返回按钮
- linux kernel ABC #1 中断环境与原子环境
- SpringMVC中的异步提交表单
- monkeytalk 启动、关闭 android应用程序 解决方法
- resizable
- UVA 1422 Processor(二分极大值极小化+优先队列)
- 二分法查找(递归与非递归法)
- fastjson null 值处理
- Tyvj专题 P1094 矩形分割
- 十个免费的 Web 压力测试工具
- win7 下安装 cent os6.3
- linux下用Apache一个IP多个网站多域名配置方法
- hdu 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- sybase数据库安装配置