uvalive 4254(二分+模拟)
2016-03-08 17:00
274 查看
分析:
大方向是二分答案,对每一秒进行模拟,判断是否能够处理完在这个时刻可以处理的任务,可以用优先队列储存当前可以执行的任务。当队列中元素不为空且里面有的元素的结束时间小于当前秒时,不能处理完;当队列中元素为空且判断完所有元素时说明可以以该速度执行。
ac代码:
大方向是二分答案,对每一秒进行模拟,判断是否能够处理完在这个时刻可以处理的任务,可以用优先队列储存当前可以执行的任务。当队列中元素不为空且里面有的元素的结束时间小于当前秒时,不能处理完;当队列中元素为空且判断完所有元素时说明可以以该速度执行。
ac代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<queue> using namespace std; struct task { int r,d,w; bool operator < (const task& a)const{ return d>a.d;} }a[10005]; bool cmp(task a,task b) { return a.r<b.r; } bool ok(int x,int n); priority_queue<task> q; int main() { //freopen("test.txt","r",stdin); int cas; scanf("%d",&cas); while(cas--) { int n; scanf("%d",&n); int mmax=0; for(int i=0;i<n;i++) { scanf("%d%d%d",&a[i].r,&a[i].d,&a[i].w); mmax+=a[i].w; } sort(a,a+n,cmp); int lb=0,ub=mmax; while(ub-lb>1) { int mid=(ub+lb)/2; if(ok(mid,n)) ub=mid; else lb=mid; } printf("%d\n",ub); } } bool ok(int x,int n) { while(!q.empty()) q.pop(); int i=0,j=0; while(1) { while(a[i].r<=j&&i<n) q.push(a[i++]); int now=x; while(now!=0&&(!q.empty())) { task tmp=q.top(); q.pop(); int m=min(now,tmp.w); now-=m; tmp.w-=m; if(tmp.w) q.push(tmp); } j++; if(!q.empty()&&q.top().d<=j) return false; if(q.empty()&&i==n) return true; } }
相关文章推荐
- swift学习资料
- 深入浅出Nginx之二【基本配置】
- tomcat maven 启动配置
- java并发编程:线程安全管理类--原子操作类--AtomicLongFieldUpdater<T>
- jquery 事件冒泡 解决 ie firefox 兼容性问题
- 标识
- CentOS 7.1 配置 postfix 服务发邮件
- 图像处理和图像识别中常用的OpenCV函数
- Python -- 计算文件的md5值
- 使用CentOS/RHEL防火墙
- slf4j日志接口技术介绍
- 随机采样方法整理与讲解(MCMC、Gibbs Sampling等)
- Send an email using Telnet
- 共享MFC DLL的规则DLL 、带静态链接MFC的规则DLL和MFC扩展DLL区别
- Android TextInputLayout修改提示信息文字颜色
- 事务隔离
- 抛出自定义异常,spring AOP事务不回滚的解决方案
- 深入浅出Nginx之一【简介与环境搭建】
- HDU2112 HDU Today(关于最短路和map)
- php读取网络文件 curl, fsockopen ,file_get_contents 几个方法的效率对比