题意:有n个任务,每个任务有三个参数,r,d,w,表示该任务必须在[r,d]之间执行,工作量是w,处理器执行速度可以变化,当执行速度是s的时候,

一个工作量是w的任务需要需要的执行时间是w/s个工作单位,另外,任务不一定要连续的执行,可以分成若干块,求出处理器执行过程中最大速度的最小值,

速度必须是整数。

析:首先是二分这个速度,然后去判断是不是成立,判断的时候要用到优先队列,把把所有的任务按开始时间排序,然后去枚举每个时间点,

用优先队列去维护一个结束时间早的优先,在每个时间点判断是不是能完成任务,完不成就是不是成立,完成就继续向下枚举。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e4 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int l, r, w;
bool operator < (const Node &p) const{
return r > p.r;
}
};
Node a[maxn];
inline int cmp(const Node &lhs, const Node &rhs){ return lhs.l < rhs.l; } bool judge(int mid){
priority_queue<Node> pq;
int cnt = 0;
for(int i = 2; i <= m; ++i){
while(cnt < n && a[cnt].l < i) pq.push(a[cnt++]);
int tmp = mid;
while(tmp && pq.size()){
Node u = pq.top(); pq.pop();
if(u.r < i) return false;
if(tmp >= u.w) tmp -= u.w;
else{
u.w -= tmp;
pq.push(u);
break;
}
}
}
return cnt == n && pq.empty();
} int solve(){
int l = 1, r = 10000;
while(l < r){
int mid = (l + r) >> 1;
if(judge(mid)) r = mid;
else l = mid + 1;
}
return l;
} int main(){
int T; cin >> T;
while(T--){
scanf("%d", &n);
m = 1;
for(int i = 0; i < n; ++i){
scanf("%d %d %d", &a[i].l, &a[i].r, &a[i].w);
m = max(m, a[i].r);
}
sort(a, a+n, cmp);
printf("%d\n", solve());
}
return 0;
}

UVaLive 4254 Processor (二分+优先队列)的更多相关文章

  1. UVALive 4254 Processor ——(二分+优先队列处理)

    题目是求最小化最大值,很显然是二分,但是二分以后怎么判断mid是否可行并不容易. 代码参考了网上一个博客的代码.巧妙之处在于一秒一秒的考虑,这样可以把处理速度mid直接转化成1秒内实际的量来解决(避免 ...

  2. UVALive 4254 Processor(二分)

    题目链接 题意 有n个任务,每个任务有三个参数ri,di和wi,表示必须在时刻[ri,di]之内执行,工作量为wi.处理器执行速度可以变化,当执行速度为s时,工作量为wi.处理器的速度可以变化,当执行 ...

  3. uva 1422 - Processor(二分+优先队列)

    题目链接:uva 1422 - Processor 题目大意:有一个机器要处理一些问题,给出这些问题可以开始的时间和必须完成的时间,以及任务的工作量,问说机器必须以最少每秒多少得工作量才能完成这些任务 ...

  4. UVa LA 4254 - Processor 二分,贪心 难度: 1

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  5. codeforces 377B Preparing for the Contest 二分+优先队列

    题目链接 给你m个bug, 每个bug都有一个复杂度.n个人, 每个人有两个值, 一个是能力值, 当能力值>=bug的复杂度时才可以修复这个bug, 另一个是雇佣他需要的钱,掏一次钱就可以永久雇 ...

  6. hdu1839(二分+优先队列,bfs+优先队列与spfa的区别)

    题意:有n个点,标号为点1到点n,每条路有两个属性,一个是经过经过这条路要的时间,一个是这条可以承受的容量.现在给出n个点,m条边,时间t:需要求在时间t的范围内,从点1到点n可以承受的最大容量... ...

  7. CF802O-April Fools‘ Problem(hard)【wqs二分,优先队列】

    正题 题目链接:https://www.luogu.com.cn/problem/CF802O 题目大意 \(n\)天每条有\(a_i\)和\(b_i\). 每条可以花费\(a_i\)准备至多一道题, ...

  8. UVALive 6093 Emergency Room --优先队列实现的模拟

    题意:给n个医生,这些医生有一个上班时间,然后给一些病人,病人有一个到达的时间,以及一些诊断,诊断有property(优先级)和duration(诊断时间)这两个属性,每个病人可能要诊断多次,最后问每 ...

  9. UVALive 4223 Trucking 二分+spfa

    Trucking 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8& ...

随机推荐

  1. RocksDB

    RocksDB RocksDB is a high performance[1][2][3][4][5] embedded database for key-value data. It is a f ...

  2. php函数: set_include_path

    <?php $p =get_include_path(); $p.=PATH_SEPARATOR.'./bp/'; $p.=PATH_SEPARATOR.'./CLI/'; $p.=PATH_S ...

  3. 我的Android进阶之旅------>使用ThumbnailUtils类获取视频的缩略图

    今天看了一段代码,是关于获取视频的缩略图的,让我认识了一个ThumbnailUtils类,代码如下. Bitmap bitmap = ThumbnailUtils.createVideoThumbna ...

  4. Coin和Token有什么区别

    在币圈,经常可以听到“coin”和“token”这些词汇,他们究竟分别代表什么,有什么区别呢?下面本文就和大家一起来扒一扒. 什么是coin? coin (包括山寨coin)是一种数字货币,它通过加密 ...

  5. java ClassLoader类加载器

    原文 首先来了解一下字节码和class文件的区别: 我们知道,新建一个java对象的时候,JVM要将这个对象对应的字节码加载到内存中,这个字节码的原始信息存放在classpath(就是我们新建Java ...

  6. API的理解和使用——全局命令

    全局命令 命令 功能 set 创建键值对 keys 遍历查看所有键 exists 判断一个键是否存在,1存在,0不存在 dbsize 当前数据库中有多少个键 del 删除一个或多个键 expire 设 ...

  7. 编辑框的WM_MOUSELEAVE和WM_MOUSEHOVER使用

    // 参考资料 // http://www.cnblogs.com/weiqubo/archive/2011/04/14/2016323.html 最近工作需要,需要自定义编辑框,改写编辑框CEdit ...

  8. linux应用之jdk环境的安装(centos)

    一.yum安装 1.执行:yum search jdk 已加载插件:fastestmirror, securityLoading mirror speeds from cached hostfile ...

  9. C# 多线程、控制线程数提高循环输出效率

    C#多线程及控制线程数量,对for循环输出效率. 虽然输出不规律,但是效率明显提高. 思路: 如果要删除1000条数据,只使用for循环,则一个接着一个输出.所以,把1000条数据分成seed段,每段 ...

  10. SpringBoot_Exception_02_Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE:run

    一.现象 上一个异常解决之后,出现了这个异常: [WARNING] The requested profile "pom.xml" could not be activated b ...