LA 4254 Processor (单调队列 + 二分)
2016-04-25 21:21
393 查看
题意:有n个任务,每个任务有三个参数,ri,di,wi,表示在ri di之内需要执行完工作量为wi的任务,任务可以分块执行,求执行过程中的最大速度的最小值。速度需为整数。
分析:二分判断,判断有些复杂,要用到单调队列,写的挺烂的,但是一遍过了。
分析:二分判断,判断有些复杂,要用到单调队列,写的挺烂的,但是一遍过了。
#include <queue> #include <vector> #include <cstdio> #include <algorithm> #include <iostream> #define MAXN 10002 using namespace std; int n,T; struct thing { double r,d,w; } test[MAXN]; bool camp(thing a,thing b) { if(a.r == b.r) return a.d < b.d; return a.r < b.r; } struct Camp { bool operator() (int a,int b) { return test[a].d > test[b].d; } }; priority_queue <int,vector<int>,Camp> q; bool jud(double v,const thing test[]) { thing Test[MAXN]; for(int i = 1;i <= n;i++) Test[i] = test[i]; while(!q.empty()) q.pop(); int now = 1,num = 0; q.push(1); double pos = Test[1].r; while(!q.empty()) { thing &u = Test[q.top()]; if(u.w/v > u.d - pos) return false; double dis = now == n ? u.w/v : min(u.w/v,Test[now+1].r - pos); pos += dis; u.w -= dis*v; if(pos == Test[now+1].r) { now++; q.push(now); } if(u.w < 0.000001) { q.pop(); num++; } if(q.empty() && num != n) { now++; pos = Test[now].r; q.push(now); } } return true; } int main() { cin.sync_with_stdio(false); cin>>T; while(T--) { cin>>n; for(int i = 1;i <= n;i++) cin>>test[i].r>>test[i].d>>test[i].w; sort(test+1,test+1+n,camp); int s = 1,t = 10001; while(s != t) { int mid = (s + t) / 2; if(jud(mid,test)) t = mid; else s = mid + 1; } cout<<s<<endl; } }
相关文章推荐
- 解决ListView的item监听事件个子控件监听事件冲突问题
- 根据select下拉框选择的值,向form表单添加所要显示的内容的方法
- Impala
- HTTP协议基本知识
- 第八周总结
- 一周总结
- 冲刺阶段第八天
- 数据库 --> MySQL存储引擎介绍
- [HDOJ4325]Flowers(树状数组 离散化)
- antlr.collections.AST.getLine()I异常
- 稀疏矩阵的十字链表存储
- C经典 打印二维数组五个学生三门课的每门课平均成绩及总课程的平均的成绩
- 线程与进程
- mysql 数据库问题com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟
- git分支管理命令
- 从风投角度看区块链将会颠覆的三个行业
- 团队作业(四)
- NSNotificationCenter的使用
- 笔试有感