题目

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的更多相关文章

  1. Uva LA 3177 - Beijing Guards 贪心,特例分析,判断器+二分,记录区间内状态数目来染色 难度: 3

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

  2. UVa 1335 Beijing Guards (二分+贪心)

    题意:n 个人成一个圈,每个人想要 ri 种不同的礼物,要求相邻两个人没有相同的,求最少需要多少礼物. 析:如果 n 是偶数,那么答案一定是相邻两个人的礼物总种数之和的最大值,那么如果是奇数,就没那么 ...

  3. Uva 11520 - Fill the Square 贪心 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  4. UVaLive 4254 Processor (二分+优先队列)

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

  5. UVA 1149 Bin Packing 二分+贪心

    A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the samele ...

  6. Uva LA 3902 - Network 树形DP 难度: 0

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

  7. UVA LA 7146 2014上海亚洲赛(贪心)

    option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...

  8. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  9. 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心

    /** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...

随机推荐

  1. tf.InteractiveSession()和tf.Session()

    tf.InteractiveSession()适合用于python交互环境 tf.Session()适合用于源代码中 1.tf.InteractiveSession() 直接用eval()就可以直接获 ...

  2. 虚拟机linux下安装tomcat外部可访问

    1.解压tomcat压缩包 tar -zxvf apache-tomcat 2.启动tomcat 进入bin目录下 ./catalina.sh run  (startup.sh不会显示日志信息) 3. ...

  3. web服务器集群(多台web服务器)后session如何同步和共享

    在访问量上去以后,很多人会采用web集群的方式在满足逐渐增长的用户量.这时候就不得不面对一个问题,那就是在多个服务器下,每次请求都会因为负载均衡而分配到不同的服务器上.用户在登录服务器后,下一次请求被 ...

  4. 谷歌技术"三宝"之MapReduce

    江湖传说永流传:谷歌技术有"三宝",GFS.MapReduce和大表(BigTable)! 谷歌在03到06年间连续发表了三篇很有影响力的文章,分别是03年SOSP的GFS,04年 ...

  5. redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: 断开的管道 (Write failed)

    昨晚,包发到测试环境中,出现redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: 断开的 ...

  6. LOJ #10132. 「一本通 4.4 例 3」异象石

    题目地址 LOJ 题解 神仙思路.思路参考自<算法竞赛进阶指南>. 考虑维护dfs序中相邻两个石头的距离,那么每次?的答案就是sum/2(首尾算相邻) 然后维护一下拿个平衡树/set维护一 ...

  7. oracle常用的数据字典查询语句

    select * from all_source where owner='user_name' and type = 'PROCEDURE' and upper(text) like upper(' ...

  8. Mac cnpm安装失败及解决方案

    首先安装node 官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/ 淘宝镜像安装cnpm, 在终端输入: npm install -g cnpm --registry=h ...

  9. Linux下更新Git

     查看git版本,卸载旧版本(如果没有安装git请直接到下一步) git --version yum remove git  安装依赖软件 yum install curl-devel expat-d ...

  10. Java中的CAS实现原理

    一.什么是CAS? 在计算机科学中,比较和交换(Conmpare And Swap)是用于实现多线程同步的原子指令. 它将内存位置的内容与给定值进行比较,只有在相同的情况下,将该内存位置的内容修改为新 ...