题目链接

题意:

  有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的更多相关文章

  1. 反射动态创建不同的Processor

    1. 定义抽象方法 public abstract class BaseProcesser    {        public abstract void GetCustomerReportCard ...

  2. processor, memory, I/O

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION 3.3 INTERCONNECTION S ...

  3. 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 ...

  4. instruction-set architecture Processor Architecture

    Computer Systems A Programmer's Perspective Second Edition We have seen that a processor must execut ...

  5. 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 ...

  6. Processor Speculative & pipeline

    https://en.wikipedia.org/wiki/Instruction-level_parallelism https://en.wikipedia.org/wiki/Instructio ...

  7. 深入学习Heritrix---解析处理器(Processor)(转)

    深入学习Heritrix---解析处理器(Processor) 本节解析与处理器有关的内容. 与处理器有关的主要在以下几个类:Processor(处理器类),ProcessorChain(处理器类), ...

  8. Heritrix源码分析(八) Heritrix8个处理器(Processor)介绍(转)

    本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/643367       本博客已迁移到本人独立博客: http://www.yun5u ...

  9. 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 ...

随机推荐

  1. android模拟器经常出现的一些问题及解决办法

    1.Unable to get view server version from device exlipse下编写好android应用程序时候,右键项目 run as android applica ...

  2. c++ 数据持久层研究(一)

    C++ORM框架自动生成代码数据库  用过Java的都知道SSH框架,特别对于数据库开发,Java领域有无数的ORM框架,供数据持久层调用,如Hibernate,iBatis(现在改名叫MyBatis ...

  3. Android开发之位置定位详解与实例解析(GPS定位、Google网络定位,BaiduLBS(SDK)定位)

    在android开发中地图和定位是很多软件不可或缺的内容,这些特色功能也给人们带来了很多方便.定位一般分为三种发方案:即GPS定位.Google网络定位以及基站定位 最简单的手机定位方式当然是通过GP ...

  4. Android 开发第二天

    开发入门HelloWorld 首先打开开发工具 第一步 第二步 效果图 以后可以点击一直下去 第三步骤介绍一下里面项目的作用 SRC是用来保存源代码的东西MainAcrivity.java主视图res ...

  5. javascript进击(四)HTML DOM

    HTML DOM (文档对象模型) 什么是DOM? DOM 是 W3C(万维网联盟)的标准. DOM 定义了访问 HTML 和 XML 文档的标准. W3C 文档对象模型 (DOM) 是中立于平台和语 ...

  6. synchronized关键字小结(一)

    1. synchronized同步方法 1) synchronized修饰方法,表示方法是同步的,当某线程进入并拿到当前整个对象的锁时 a. 其他synchronized方法排队等锁 b. 非sync ...

  7. web 电子商务网站开发笔记整理

    js只保留整数,向上取整,四舍五入,向下取整等函数 来源:ab蓝学网整理 时间:2014-07-09 点击:30131 简介:WEB前端|1.丢弃小数部分,保留整数部分parseInt(5/2)2.向 ...

  8. js选中checkbox赋值给文本框

    //js $(function(){ var name=""; var kmname=[]; var n= $("input[type=checkbox]"). ...

  9. C#做的一个加密/解密的类

    转自:http://www.16aspx.com/Article/3904 using System; using System.Security.Cryptography; using System ...

  10. Java分布式缓存框架

    http://developer.51cto.com/art/201411/457423.htm 在开发中大型Java软件项目时,很多Java架构师都会遇到数据库读写瓶颈,如果你在系统架构时并没有将缓 ...