题目链接

题意:

  有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. dmesg 程序崩溃调试

    [root@localhost log]# cat -n /root/xx.c #include <stdio.h> void func(char *p) { *p = 'p'; } in ...

  2. [转] React Native Navigator — Navigating Like A Pro in React Native

    There is a lot you can do with the React Native Navigator. Here, I will try to go over a few example ...

  3. 对ContentProvider中getType方法的一点理解

    在上篇博客中我们介绍了自定义ContentProvider,但是遗漏掉了一个方法,那就是getType,自定义ContentProvider一般用不上getType方法,但我们还是一起来探究下这个方法 ...

  4. nyoj 24 素数距离问题

    素数距离问题 时间限制:3000 ms  |            内存限制:65535 KB 难度:2   描述 现在给出你一些数,要求你写出一个程序,输出这些整数相邻最近的素数,并输出其相距长度. ...

  5. C#相关时间DateTime格式化

    C#代码中时间转换为2016-01-24 12:12:12需要如下操作: DateTime.Parse(sj).ToString("yyyy-MM-dd HH:m:ss") 但是O ...

  6. Asp.net上传出现“超过了最大请求长度”的问题解决方法

    在开发ASP.NET网站后台管理系统时,我们可能会遇到这样的问题:上传大于4M的文件时,会提示错误:错误信息如下: 1.异常详细信息:超过了最大请求长度. 2.引发异常的方法:Byte[] GetEn ...

  7. jquery无法读取json文件问题

    jquery无法读取json文件,如:user.json文件无法读取.把user.json文件的后缀名修改为aspx,文件内容不变,则可以读取~ 原理不懂!~~

  8. react 编写组件 五

    看以下示例了解如何定义一个组件 // 定义一个组件LikeButton var LikeButton = React.createClass({ // 给state定义初始值 getInitialSt ...

  9. OC加强-day04

    #pragma mark 00知识回顾 //定义一个函数 函数没有返回值函数有一个参数:返回值是double 参数是两个int的block void test(int a); void test(do ...

  10. iOS8 【xcode6中添加pch全局引用文件】

    前沿:xcode6中去掉了pch,为了一些琐碎的头文件引用,加快了 编译速度! xcode6之前的版本建项目就自动添加了是这样的: xcode6后的版本要自己手动的添加步骤如下: 1)  2) 3) ...