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个木块,堆 ...
随机推荐
- c# 传入c++dll 回调函数输出byte 导致 bug
- nginx rewrite 指令
ginx通过ngx_http_rewrite_module模块支持url重写.支持if条件判断,但不支持else. 该模块需要PCRE支持,应在编译nginx时指定PCRE源码目录, nginx安装方 ...
- 2014西安赛区C题
将A[i]同他后面比他小的建边,然后求最大密度子图 #include <iostream> #include <algorithm> #include <string.h ...
- sublime text 入门
sublime text3入门教程 2017年07月19日 09:15:51 阅读数:13736 作者:sam976 转载需征得作者本人同意,谢谢. 1.介绍 所谓工欲善其事必先利其器,编码过程合理熟 ...
- 复习-css元素定位
css元素定位 <style type="text/css"> body{ margin: 15px; font-family: "Adobe 宋体 Std ...
- Redis初探-Redis安装
官网地址:https://redis.io/download 最新版本是4.0,在这里本人下的是3.2 使用rz命令可以将Redis上传到Linux系统 首先要确定Linux上是否安装了gcc,没有则 ...
- 极路由hosts
cat /etc/hosts 127.0.0.1 localhost tw-vars hiwifi 192.168.199.1 t.w tw t 4006024680.com www.40060246 ...
- Python制作AI贪吃蛇
前提:本文实现AI贪吃蛇自行对战,加上人机对战,文章末尾附上源代码以及各位大佬的链接,还有一些实现步骤,读者可再次基础上自行添加电脑VS电脑和玩家VS玩家(其实把人机对战写完,这2个都没什么了,思路都 ...
- Codeforces 17E Palisection - Manacher
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个串$s$询问,有多少对回文子串有交. 好像很简单的样子. 考虑能不能直接求,感觉有点麻烦.因为要考虑右端点在当前回文子串内还有区间包含 ...
- bzoj2124: 等差子序列线段树+hash
bzoj2124: 等差子序列线段树+hash 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2124 思路 找大于3的等差数列其实就是找等于 ...