UVA 1422 Processor(二分极大值极小化+优先队列)
2015-07-14 15:53
501 查看
题意:
给定n个任务,每个任务必须在时间[R,D]内完成,每个任务工作量为W,问最小完成速率使得所有工作完成。思路:
二分求下界的问题,判断的时候利用优先队列,由于时间只有20000,去枚举每个单位时间,看要给分配个那个任务,这步利用优先队列,按d越小越先出队,因为d越小肯定要越快完成越好。mymy codecode
[code]#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 ; 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; }
相关文章推荐
- linux内核完全剖析 学习笔记 打字太累 截图 持续更新
- 自己改的水平滑块
- linux chmod命令更改文件的读写执行权限
- SSO(Single Sign On)系列(三)--CAS单点登录
- MyReport有填报功能了!!!MyReport.Form表单引擎
- ubuntu自动备份数据库
- Android应用Activity、Dialog、PopWindow、Toast窗口添加机制及源码分析 《四》-PopWindow
- c++ STL stack 内存布局简析
- Android ListView滑动过程中控件显示重复/错误问题之原理分析及解决方案
- c3p0和dbcp数据源配置
- Linux 下挂载硬盘的方法
- SSO(Single Sign On)系列(二)--SSO原理
- 转:MAVEN常用命令
- nginx 重写 rewrite 基础及实例
- 插入、
- Tyvj专题 P1083 分糖果
- 计算机视觉模式识别用到的几本优化的书籍
- linux下多进程同时操作文件
- Angular $parse
- xshell连接虚拟机ubantu系统问题总结