uva_1422 Processor
题意:
有n个任务, 每个任务要在规定的时间[l, r]内完成, 工作量为 w, 每个任务可以分开完成。
求, 使得所有任务都完成的最大速度的最小值。
思路:
最大值最小问题, 二分。
因为是要完成所有任务, 所以先按开始时间排序, 接下来二分速度。
因为任意两个任务之间的关系只有两种, 1)相交或者包含 2)相切或者相离
如果是情况 2) 那么不需要特殊处理, 按顺序处理过去即可。
如果是情况 1) 那么需要将这个时间段内的任务按照结束时间来进行处理, 结束时间小的优先完成。
然后枚举时间, 从1 开始处理过去, 看是否能处理完所有任务即可。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 10010
#define MAXM 100
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {printf("%d\n", x);}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
struct node
{
int l;
int r;
int t;
int no;
bool operator < (const struct node &y) const
{
return r > y.r;
}
};
int n, sum;
struct node f[MAXN];
int w[MAXN];
bool cmp(const struct node &x, const struct node &y)
{
return x.l == y.l? x.r < y.r : x.l < y.l;
}
void read()
{
sum = ;
scanf("%d", &n);
for(int i = ; i < n; i ++)
{
scanf("%d %d %d", &f[i].l, &f[i].r, &f[i].t);
sum += f[i].t;
f[i].no = i;
}
sort(f, f + n, cmp);
}
bool is_ok(int x)
{
priority_queue <struct node> Q;
for(int i = ; i < n; i ++)
w[f[i].no] = f[i].t;
int i = ;
int pos = ;
while(true)
{
while(i < n && f[i].l <= pos) Q.push(f[i ++]); int ts = x;
while(!Q.empty() && ts)
{
struct node temp = Q.top(); if(temp.r <= pos) return false; w[temp.no] -= ts;
if(w[temp.no] > )
ts = ;
else if(w[temp.no] <= )
{
ts = -w[temp.no];
Q.pop();
}
} if(i == n && Q.empty()) return true;
pos ++;
}
return false;
}
int get_ans()
{
int l = , r = sum;
while(l <= r)
{
int mid = (l + r) / ;
if(is_ok(mid))
r = mid - ;
else
l = mid + ;
}
return l;
} int main()
{
int T;
scanf("%d", &T);
while(T --)
{
read();
printf("%d\n", get_ans());
}
return ;
}
uva_1422 Processor的更多相关文章
- 反射动态创建不同的Processor
1. 定义抽象方法 public abstract class BaseProcesser { public abstract void GetCustomerReportCard ...
- processor, memory, I/O
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION 3.3 INTERCONNECTION S ...
- improve performance whilemaintaining the functionality of a simpler and more abstract model design of processor hardware
Computer Systems A Programmer's Perspective Second Edition In this chapter, we take a brief look at ...
- instruction-set architecture Processor Architecture
Computer Systems A Programmer's Perspective Second Edition We have seen that a processor must execut ...
- simplify the design of the hardware forming the interface between the processor and thememory system
Computer Systems A Programmer's Perspective Second Edition Many computer systems place restrictions ...
- Processor Speculative & pipeline
https://en.wikipedia.org/wiki/Instruction-level_parallelism https://en.wikipedia.org/wiki/Instructio ...
- 深入学习Heritrix---解析处理器(Processor)(转)
深入学习Heritrix---解析处理器(Processor) 本节解析与处理器有关的内容. 与处理器有关的主要在以下几个类:Processor(处理器类),ProcessorChain(处理器类), ...
- Heritrix源码分析(八) Heritrix8个处理器(Processor)介绍(转)
本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/643367 本博客已迁移到本人独立博客: http://www.yun5u ...
- codeforces 677B B. Vanya and Food Processor(模拟)
题目链接: B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes i ...
随机推荐
- java15 IO装饰设计模式
IO装饰设计模式:(IO中使用了装饰设计模式) 节点流可以直接从源读取数据,处理流就是对节点流的包装,这就是装饰,装饰就是对原有的流的性能的提升.比如买的车,马力不够,就进行装饰,使其马力增大. 装饰 ...
- Design Of A Modern Cache
http://highscalability.com/blog/2016/1/25/design-of-a-modern-cache.html MONDAY, JANUARY 25, 2016 AT ...
- binutil 工具-----C分析工工具
binutils-- a tools set * ld - the GNU linker. * as - the GNU assembler. * addr2line - Converts addre ...
- 在不同平台上CocosDenshion所支持的音频格式
在大多数平台上,cocos2d-x调用不同的SDK API来播放背景音乐和音效.CocosDenshion在同一时间只能播放一首背景音乐,但是能同时播放多个音效. 背景音乐 Platform supp ...
- 认识copy关键
首先先引用阳神Sunny博客中的一道面试题: 用@property声明的NSString(或NSArray,NSDictionary)经常使用copy关键字,为什么?如果改用strong关键字,可能造 ...
- select组件
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- tarball文件安装的大概流程
./configure这个步骤就是在创建 Makefile 这个文件罗!通常程序开发者会写一支 scripts 来检查你的 Linux 系统.相关的软件属性等等,这个步骤相当的重要, 因为未来你的安装 ...
- JS火狐与IE的差别
function isIE(){ //ie? ) return true; else return false; } if(!isIE()){ //firefox innerText define H ...
- 移动终端学习1:css3 Media Queries简介
移动终端学习之1:css3 Media Queries简介 1.简介 这篇文章写的不错,我就不重复了,来个链接:http://www.w3cplus.com/content/css3-media-qu ...
- 关于redhat6的服务说明
服务名称 功能 默认 建议 备注说明 NetworkManager 主要用于图形网络连接管理 开启 关闭 对服务器无用 abrt-ccpp Automated Bug Reporting Tool 开 ...