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 ...
随机推荐
- android91 代码注册广播接收者
Activity: package com.itheima.register; import android.os.Bundle; import android.app.Activity; impor ...
- RHCA学习笔记:RH442-Unit9内核定时与进程延时
Unit 9 Kernel Timing and Process Latency 内核定时与进程延时 学习目标: A.了解CPU 是怎样追踪时间的 B.调整CPU的访问次数 C.调整调度延时 D. ...
- sed命令详解--转
1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保存结果.默认情况下,所有的输出行都被打印到屏幕上. sed编辑器逐行处理文件(或输入),并将结果发送到屏幕.具体过程如下 ...
- java注解研究
注解作用 常见的作用有以下几种: 生成文档.这是最常见的,也是java 最早提供的注解.常用的有@see @param @return @author等. 跟踪代码依赖性,实现替代配置文件功能.比较常 ...
- 转:通过API获取和创建 Oracle GL Account Code Combination ID’s (CCID’s)的几种方法汇总
1] FND_FLEX_EXT.GET_COMBINATION_ID: This API Finds combination_id for given set of key flexfield seg ...
- IE6下Png透明最佳解决方案(推荐) Unit PNG Fix
引自:http://www.yeeyan.org/articles/view/98510/67784 网络上解决IE6下Png透明解决方案有很多,例如 IE PNG Fix from TwinHeli ...
- jBPM开发入门指南
http://blog.csdn.net/eric474470/article/details/7665265 工作流虽然还在不成熟的发展阶段,甚至还没有一个公认的规范标准.但其应用却已经在快速展开, ...
- OI路上-NOIP100天冲刺计划
学OI已经9个月了,可是自己水平还是那样的弱QWQ. 现在离NOIP还有差不多100天的时间. 晚上辗转反侧发现了自己的一些问题: (1)DP还经常没思路. (2)搜索恶心题还不想写. (3)有时候也 ...
- GCC --verbose选项, -lpthread 和-pthread的区别
verbose的意思是冗长的,繁杂的.顾名思义,gcc --verbose 的意思就是打印出编译连接时的详细信息. 参考stackoverflow中的文章结合自己机器的信息给出分析(其实也就是翻译了一 ...
- Unix环境高级编程学习笔记——fcntl
写这篇文正主要是为了介绍下fcntl,并将我自己在学习过程中的一些理解写下来,不一定那么官方,也有错误,希望指正,共同进步- fcntl: 一个修改一打开文件的性质的函数.基本的格式是 int fcn ...