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个木块,堆 ...
随机推荐
- 使用PageHelper插件分页结合mybatis返回的列表个数不对问题解决
问题描述:spring mvc+mybatis项目中,当使用PageHelper插件进行分页查询时,查到的总数据量值是正确的,但是查询当前页返回的列表个数不对.比如每页查询10条,返回2条或者3条.r ...
- git----------git:如何让git识别我修改了文件夹名字和文件名字的大小写问题。
修改每个项目里面的隐藏的.git文件里面的config文件.将箭头指的原本是true改成false.
- h5 的localStorage和sessionStorage存到缓存里面的值是string类型
localStorage永久存在,不手动清除永远存在:sessionStorage 一次会话的浏览器关闭就自动清除 h5 的localStorage和sessionStorage 存到缓存里面的值都是 ...
- docker基本部署
一.基本概念docker 1.镜像(Image) Docker 镜像就是一个只读的模板. 例如:一个镜像可以包含一个完整的 ubuntu 操作系统环境,里面仅安装了 Apache 或用户需要的其它应用 ...
- Linux 管理服务启动工具
工具:ntsysv(图形,可以关闭开启服务) 安装包:ntsysv-1.3.30.2-2.el5 工具:chkconfig –list(文字,开启关闭服务) 自定义加服务:执行脚本放入:/etc/in ...
- final修饰符与多态
知识点一.final 最终的可以修饰属性.方法.类1.final修饰的属性,表示常量,初始化以后值不能改变.final修饰引用数据类型的变量,引用地址不能改变.2.final修饰类,不能被继承.比如: ...
- 委托&&异步
private void ShowMessage(string message) { this.BeginInvoke(new MethodInvoker(delegate { txtSysMessa ...
- 关于vim的折叠
参考: http://www.cnblogs.com/fakis/archive/2011/04/14/2016213.html 和 这篇文章: https://blog.csdn.net/benda ...
- 微信小程序实现部分双向数据绑定(为input、picker、textarea编写统一的更新数据逻辑)
wepy开发小程序 以input为例,微信小程序没有数据双向绑定,input要显示绑定的数据即value等于一个绑定的量 <input type="text" value=& ...
- Learning-MySQL【5】:数据的操作管理
一.插入数据 1.为表的所有字段插入数据 通常情况下,插入的新纪录要包含表的所有字段 INSERT 语句有两种方式可以同时为表的所有字段插入数据,第一种方式是不指定具体的字段名,第二种方式是列出表的所 ...