uvalive 4254(二分)
来源:互联网 发布:古筝软件哪个好 编辑:程序博客网 时间:2024/06/15 00:19
题意:有n个任务,给出了每个任务的起始时间和终止时间还有工作量w,处理任务的速度为s时,任务会花费 w / s时间,然后每个任务都要在规定时间内完成,但任务可以不用连续时间块内完成,要求出让所有时间都顺利完成的最大速度的最小值。
题解:一般要求最大XX最小值时用二分法,可以二分出一个速度,拿去判断是否可行。在判断一个速度是否可以使任务完成时,用一个优先队列(终止时间小的排在前面)存所有未完成且可以开始进行的所有任务,然后模拟每一秒的任务量让优先级最大的任务先用,如果用不完就次之,然后如果任务未完成就继续加入队伍,最后如果所有任务都完成就true,超出时间就false。
#include <stdio.h>#include <queue>#include <algorithm>using namespace std;const int N = 10005;struct P {int st, en, w;friend bool operator < (const P &a, const P &b) {return a.en > b.en;}}p[N];int n;int cmp(P a, P b) {return a.st < b.st;}bool judge(int x) {priority_queue<P> q;int t = 1, i = 0;while (1) {while (i < n && t >= p[i].st)q.push(p[i++]);int re = x;while (re != 0 && !q.empty()) {P u = q.top();q.pop();int temp = min(re, u.w);re -= temp;u.w -= temp;if (u.w != 0)q.push(u);}t++;if (!q.empty() && q.top().en <= t)return false;if (q.empty() && i == n)return true;}}int main() {int t;scanf("%d", &t);while (t--) {scanf("%d", &n);int l = 0, r = N;for (int i = 0; i < n; i++) {scanf("%d%d%d", &p[i].st, &p[i].en, &p[i].w);}sort(p, p + n, cmp);while (l < r) {int mid = (l + r) / 2;if (judge(mid))r = mid;elsel = mid + 1;}printf("%d\n", l);}return 0;}
0 0
- uvalive 4254(二分)
- UVALive 4254 二分
- uvalive 4254(二分+模拟)
- UVALive - 4254 Processor 二分+优先队列
- uvalive 4254 Processor处理器 (二分模拟+贪心)
- UVALIVE 3635 Pie 二分
- UVALive 6144 Radiation 二分
- uvalive 2949(二分+贪心)
- Clock Splitter+uvalive+二分
- UVALive - 3635 Pie 二分
- uvalive 4725(贪心 + 二分)
- UVALive 6525 二分匹配
- UVALive 3635-Pie-二分
- UVALive 3177-贪心+二分
- UVALive 3635 Pie 【二分】
- UVALive 7261(二分)
- UVALive 6694 - 二分
- UVALive 3635 Pie 二分查找
- android开发 sqlite设置本地时间
- 常用的android弹出对话框
- artDialog插件的详细使用
- 中国剩余定理 ( POJ 1006 )
- matlab函数 bsxfun
- uvalive 4254(二分)
- Android----画柱状图和饼图
- atitit.获取connection hibernate4
- 关于eclipse字体与主体颜色的配置
- PAT(B)1005. 继续(3n+1)猜想 (25)
- 单身的原因 -- (文/佚名)
- 计算分数精确值
- Linux内存管理(2) - buddy系统
- hiho 挑战赛7(有钱就是任性-dp与质数的因子)