题意:有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. Vue 填坑系列(持续更新...)

    1.遇到页面显示不更新,数据已更新情况 vue-cli中: this.$nextTick(function () { this.x=x; })     以js引入vue的网页中: this.$set( ...

  2. AWS:2.根设备类型、EC2生命周期状态、User Data

    主要内容 1.根设备类型 linux: /dev/sda1 windows: 系统盘 2.实例生命周期 生命周期状态:停止.终止.重启 3.用户数据(UserData) 实例在初始化,运行之前给定的用 ...

  3. Richard Stallman's computer

    What hardware do you use? I am using a Lemote Yeelong, a netbook with a Loongson chip and a 9-inch d ...

  4. php计算数组的维数

    function array_dim($arr){ if(!is_array($arr)) return 0; else{ $max1 = 0; foreach($arr as $item1){ $t ...

  5. Linux安装mariadb详细步骤

    1.安装mariadb yum和源码编译安装的区别? 1.路径区别-yum安装的软件是他自定义的,源码安装的软件./configure --preifx=软件安装的绝对路径 2.yum仓库的软件,版本 ...

  6. 如何在windows上创建文件名以“.”开头的文件

    比如要创建.env文件,正常会提示必须输入文件名才能创建的,但是可以在后面再加一个点就能创建了,.env.这样就可以了

  7. LeetCode——Binary Tree Postorder Traversal

    Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...

  8. memcache-session-manager(flexjson)

    MSM项目FlexJson序列化参考文档. 序号(步骤) 需求描述 jar包列表: spymemcached-2.11.1.jar memcached-session-manager-tc8-1.8. ...

  9. IOS 关于 NSUserDefault

    转载 并不是所有的东西都能往里放的.NSUserDefaults只支持: NSString, NSNumber, NSDate, NSArray, NSDictionary.   NSUserDefa ...

  10. 一小时搞明白自定义注解(Annotation)

    原文链接:http://blog.csdn.net/u013045971/article/details/53433874 什么是注解 Annotation(注解)就是Java提供了一种元程序中的元素 ...