UVA 1422 - Processor(二分+优先队列+贪心)
来源:互联网 发布:java微信卡券开发实例 编辑:程序博客网 时间:2024/05/02 00:26
题目链接:点击打开链接
题意:有n个任务, 每个任务必须在[r,d]时间段内完成, 任务量为w, 求最小执行速度, 使得可以在规定时间内完成所有任务。
思路:二分通常要和贪心搭配, 显然, d越小的, 应该优先完成, 所以我们可以用一个优先队列来维护这个信息, 然后枚举每一个时刻, 看看应该先执行那个程序。
细节参见代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<stack>#include<bitset>#include<cstdlib>#include<cmath>#include<set>#include<list>#include<deque>#include<map>#include<queue>#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;typedef long long ll;typedef long double ld;const ld eps = 1e-9, PI = 3.1415926535897932384626433832795;const int mod = 1000000000 + 7;const int INF = int(1e9);const ll INF64 = ll(1e18);const int maxn = 10000 + 10;int T,n,m,maxt;struct node { int r, d, w; node(int r=0,int d=0,int w=0):r(r),d(d),w(w) {} bool operator < (const node& rhs) const { return d > rhs.d; }}a[maxn];bool cmp(node a, node b) { return a.r < b.r || (a.r == b.r && a.d < b.d);}bool ok(int mid) { priority_queue<node> q; int cnt = 0; for(int i=1;i<=maxt;i++) { while(a[cnt].r < i && cnt < n) q.push(a[cnt++]); int res = mid; while(res != 0 && !q.empty()) { node u = q.top(); q.pop(); if(i > u.d) return false; if(u.w > res) { u.w -= res; res = 0; q.push(u); } else { res -= u.w; } } } if(cnt == n && q.empty()) return true; else return false;}int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); maxt = 0; for(int i=0;i<n;i++) { scanf("%d%d%d",&a[i].r,&a[i].d,&a[i].w); maxt = max(maxt, a[i].d); } sort(a, a+n, cmp); int l = 1, r = 20000,mid; while(r > l) { mid = (l + r) >> 1; if(ok(mid)) r = mid; else l = mid + 1; } printf("%d\n",l); } return 0;}
0 0
- UVA 1422 - Processor (二分+贪心+优先队列)
- UVA 1422 - Processor (二分+贪心+优先队列)
- UVA 1422 Processor(优先队列+贪心+二分)
- UVa 1422 - Processor(二分 + 贪心 + 优先队列)
- UVA 1422 - Processor(二分+优先队列+贪心)
- uva 1422 - Processor(二分+优先队列)
- (intermediate) UVA 贪心+二分+优先队列 1422Processor
- UVA 1422 Processor(二分极大值极小化+优先队列)
- UVA-1422(贪心+二分+优先队列)
- LA 4254 Processor(二分+贪心+优先队列)
- uva1422 - Processor 二分+优先队列
- Processor(二分搜索,优先队列)
- UVALive - 4254 Processor 二分+优先队列
- UVa 1422 Processor 解题报告(二分)
- UVA-10954 贪心+优先队列
- LA4254 Processor (贪心+二分)
- LA 4254 Processor (单调队列 + 二分)
- UVA 10954 Add All (贪心 + 优先队列)
- a标签的样式属性
- java基础-Map集合
- Android中popupWindow点击外面区域以及返回键,使popupWindow消失的方法
- vector 与 set区别
- 鸟哥的Linux私房菜(服务器)- 第一章、架设服务器前的准备工作
- UVA 1422 - Processor(二分+优先队列+贪心)
- string 与char* char[]之间的转换
- 今后怎么做才能赚到钱?读完此文你就懂了!
- fuse用户空间文件系统
- div布局
- MySQL知识(十)——连接查询与子查询
- libgdx [Audio]
- div-2
- arm-linux-gcc/ncurses的安装和使用,arm-linux-gcc: 没有那个文件或目录