UVa LA 4254 - Processor 二分,贪心 难度: 1
题目
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2255
题意
n个任务,允许时间区间为[ri, di](ri , di <= 20000),运算量为wi,可以分割,问最小运算速度
思路
明显,应该二分枚举最小运算速度,
对于时刻i来说,应该优先处理已经开始的最早结束的任务。接着,如果任务已经处理完毕,那就应该等待下一个任务-也即跳到下一个r。
那么如何选择处理任务的时间点呢?可以选择每个任务开始的时候,以这个任务(和与它开始时间相同的任务)开始,而下一个任务还没有开始的时间段来处理任务。
感想:
一开始看成了di <= 1000,因此枚举速度的区间弄错了
代码
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef tuple<int, int, int> MyTask;
typedef pair<int, double> MyPair;
const int MAXN = 1e4 + ;
MyTask tasks[MAXN];
int n; bool check(int speed) {
priority_queue<MyPair, vector<MyPair>, greater<MyPair> > que;//this one is Pair<endtime, remains>
double nowt = ;
for (int i = ; i < n;) {
nowt = get<>(tasks[i]);
while (i < n && get<>(tasks[i]) <= nowt) {
que.push(MyPair(get<>(tasks[i]), get<>(tasks[i])));
i++;
}
double nxtt = i < n ? get<>(tasks[i]) : 1e9;
while (!que.empty() && nowt < nxtt) {
int d = que.top().first;
int wi = que.top().second;
que.pop();
if (nowt > d)return false;
if ((d - nowt) * speed < wi)return false;
double addt = min((double)wi / speed, nxtt - nowt);
if (addt * speed < wi) {
que.push(MyPair(d, wi - addt * speed));
}
nowt += addt;
}
}
return true;
} int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
cin >> T;
for (int ti = ;ti <= T; ti++) {
cin >> n;
for (int i = ; i < n; i++) {
int ri, di, wi;
cin >> ri >> di >> wi;
tasks[i] = tie(ri, di, wi);
}
sort(tasks, tasks + n);
int l = , r = ;
while (l < r) {
int mid = (l + r) >> ;
if (mid == l)break;
if (check(mid)) {
r = mid;
}
else {
l = mid;
}
} cout << r << endl;
} return ;
}
UVa LA 4254 - Processor 二分,贪心 难度: 1的更多相关文章
- Uva LA 3177 - Beijing Guards 贪心,特例分析,判断器+二分,记录区间内状态数目来染色 难度: 3
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa 1335 Beijing Guards (二分+贪心)
题意:n 个人成一个圈,每个人想要 ri 种不同的礼物,要求相邻两个人没有相同的,求最少需要多少礼物. 析:如果 n 是偶数,那么答案一定是相邻两个人的礼物总种数之和的最大值,那么如果是奇数,就没那么 ...
- Uva 11520 - Fill the Square 贪心 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVaLive 4254 Processor (二分+优先队列)
题意:有n个任务,每个任务有三个参数,r,d,w,表示该任务必须在[r,d]之间执行,工作量是w,处理器执行速度可以变化,当执行速度是s的时候, 一个工作量是w的任务需要需要的执行时间是w/s个工作单 ...
- UVA 1149 Bin Packing 二分+贪心
A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the samele ...
- Uva LA 3902 - Network 树形DP 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVA LA 7146 2014上海亚洲赛(贪心)
option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心
/** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...
随机推荐
- js实现多行文本溢出省略
实现效果: css: position: relative; line-height: 20px; max-height: 60px; js: function overflowHiddon(el) ...
- NOIP2009(codevs1173)最优贸易
题目大意:给你一张有n个点m条边的有向图,每个点有一个权值,求一条1到n的路径,使得这条路径上存在两个点且他们的权值差最大. 思路:用dis[i]]记录从1到i的路径中所能得到两点间权值差的最大值,然 ...
- html5,dom操作1
<body> <script>function hwd(){ var bb=document.getElementById('bt');// alert(bb.innerHTM ...
- memcache 常用方法
<?php $memcache = new Memcache; //initialised memcahe $memcache->connect("127.0.0.1" ...
- 生成树协议stp
生成树协议应用的原因是从逻辑上阻塞交换机在物理上形成的环路.大家都知道交换机工作在二层,也就是数据链路层,根据mac地址识别主机,对三层网络无法识别,因此交换机不能隔离广播.但是在日常的工作中,为了达 ...
- P3195 [HNOI2008]玩具装箱TOY(斜率优化dp)
P3195 [HNOI2008]玩具装箱TOY 设前缀和为$s[i]$ 那么显然可以得出方程 $f[i]=f[j]+(s[i]-s[j]+i-j-L-1)^{2}$ 换下顺序 $f[i]=f[j]+( ...
- Docker Compose 一键部署Nginx代理Tomcat集群
Docker Compose 一键部署Nginx代理Tomcat集群 目录结构 [root@localhost ~]# tree compose_nginx_tomcat/ compose_nginx ...
- Docker Compose 一键部署多节点爬虫程序
Docker Compose 一键部署多节点爬虫程序 目录结构 [root@localhost ~]# tree compose_crawler/ compose_crawler/ ├── cento ...
- @Transacitonal注解不生效之spring中expose-proxy的作用与原理
几年前记得整理过,@Transacitonal注解的方法被另外一个方法调用的时候,事务是不生效的. 如果大量代码已经这么写了,这个时候抽取出去不现实,怎么办呢? 答案就是在<aop:aspect ...
- 剑指offer(14)链表中倒数第K个节点
题目描述 输入一个链表,输出该链表中倒数第k个节点. 题目分析 用两个指针来跑,两个指针中间相距k-1个节点,第一个指针先跑,跑到了第k个节点时,第二个指针则是第一个节点. 这时候两个一起跑.当第一个 ...