POJ 2970 The lazy programmer
|
The lazy programmer
Description A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is a web-designer and an executive director at the same time. The second one is a programmer. The director is so a nimble guy that the studio has already got N contracts for web site development. Each contract has a deadline di. It is known that the programmer is lazy. Usually he does not work as fast as he could. Therefore, under normal conditions the programmer needs bi of time to perform the contract number i. Fortunately, the guy is very greedy for money. If the director pays him xi dollars extra, he needs only (bi − ai xi) of time to do his job. But this extra payment does not influent other contract. It means that each contract should be paid separately to be done faster. The programmer is so greedy that he can do his job almost instantly if the extra payment is (bi ⁄ ai) dollars for the contract number i. The director has a difficult problem to solve. He needs to organize programmer’s job and, may be, assign extra payments for some of the contracts so that all contracts are performed in time. Obviously he wishes to minimize the sum of extra payments. Help the director! Input The first line of the input contains the number of contracts N (1 ≤ N ≤ 100 000, integer). Each of the next N lines describes one contract and contains integer numbers ai, bi, di (1 ≤ ai, bi ≤ 10 000; 1 ≤ di ≤ 1 000 000 000) separated by spaces. Output The output needs to contain a single real number S in the only line of file. S is the minimum sum of money which the director needs to pay extra so that the programmer could perform all contracts in time. The number must have two digits after the decimal point. Sample Input 2 Sample Output 5.00 Source Northeastern Europe 2004, Western Subregion
|
题意
有n项任务,每项任务一般需要b时间,要在d前完成,有需要的话,可以用钱加速,有公式c=b-a*x,其中x为金钱,c为完成改任务的时间,因此如果给的钱够多,一项任务可以瞬间完成。现在问若要把每个任务都及时完成,最少需要多少钱?
分析
贪心来做,按照d从小到大排序,然后遍历任务列表,计算时间,若当前时间超过该任务的d了,就找到前面完成的任务中a最大的那个,加速它来获取需要的时间,因为这样才能花费最少,如何找到a最大那个呢?我们可以使用优先队列
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
using namespace std;
typedef long long LL;
const int maxn = 1e5+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1
struct node {
int a,b,d;
bool operator < (const node &rhs)const{
return a<rhs.a;
}
}work[maxn]; int cmp(node a,node b){
return a.d<b.d;
} int main(){
// freopen("in.txt","r",stdin);
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%d%d%d",&work[i].a,&work[i].b,&work[i].d);
}
sort(work,work+n,cmp);
priority_queue<node> q;
int sum=;
double ans=0.0;
for(int i=;i<n;i++){
sum += work[i].b;
q.push(work[i]); while(!q.empty()&&sum>work[i].d){
node now = q.top();
q.pop();
int res=sum-work[i].d;
if(res>=now.b){ ans += 1.0*now.b/now.a;
sum -= now.b;
}else{
now.b -= res;
sum -= res;
ans += 1.0*res/now.a;
q.push(now);
}
}
}
printf("%.2f\n",ans); } return ;
}
POJ 2970 The lazy programmer的更多相关文章
- POJ 2970 The lazy programmer(优先队列+贪心)
Language: Default The lazy programmer Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 1 ...
- POJ 2970 The lazy programmer(贪心+单调优先队列)
A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is ...
- I - The lazy programmer 贪心+优先队列
来源poj2970 A new web-design studio, called SMART (Simply Masters of ART), employs two people. The fir ...
- poj2970 The lazy programmer 【优先队列】
A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is ...
- POJ 1337 A Lazy Worker(区间DP, 背包变形)
Description There is a worker who may lack the motivation to perform at his peak level of efficiency ...
- Keep It Simple
The KISS principle, or Keep It Simple, Stupid, spans many trades, industries, and professions. The m ...
- POJ - 1245 Programmer, Rank Thyself
POJ - 1245 Programmer, Rank Thyself Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d ...
- poj 3468(线段树+lazy思想)
题目链接:http://poj.org/problem?id=3468 思路:如果直接去做,每次都更新到叶子节点,那必然会TLE,我们可以采用lazy的思想:没必要每次更新都更新到叶子节点,只要有一个 ...
- POJ 3237 Tree (树链剖分 路径剖分 线段树的lazy标记)
题目链接:http://poj.org/problem?id=3237 一棵有边权的树,有3种操作. 树链剖分+线段树lazy标记.lazy为0表示没更新区间或者区间更新了2的倍数次,1表示为更新,每 ...
随机推荐
- Java Configuration Manager Automatic Reloading
公司一个项目的从另外一个小公司,拷贝了一个PropertyParser的类,实现的有问题,必须重启java应用才能读取新的配置. 简单的解决办法,就是每次读任何配置项时,都重新加载xxx.proper ...
- [书摘]图解HTTP 状态码
状态码类别: 1XX informational 信息性状态码 2XX Suess 成功状态码 3XX Redirection 重定向状态码 4XX Client error 客户端错误状态码 5 ...
- [工作相关] 一个虚拟机上面的SAP4HANA的简单使用维护
1.公司组织竞品分析, 选择了SAP的 SAP4HANA作为竞品 这边协助同事搭建了SAP4HANA的测试环境: 备注 这个环境 应该是同事通过一些渠道获取到的. 里面是基于这个虚拟机进行的说明:: ...
- 关于MySQL中添加数据的两种方法
下面介绍两种执行SQL命令的方法,并作出相应地总结,第一种介绍一种常规用法,下面进行做简要地分析,首先我们需要执行打开数据库操作首先创建一个MySqlConnection对象,在其构造函数中传入一个连 ...
- Bootstrap辅助类
前面的话 Bootstrap提供了一组工具类,用于辅助项目的开发.本文将详细介绍Bootstrap辅助类 文本色 通过颜色来展示意图,Bootstrap 提供了一组工具类.这些类可以应用于链接,并且在 ...
- AtCoder WTF 2019 C2. Triangular Lamps Hard
题目链接 感觉这样的题真的称得上是鬼斧神工啊,\(\text{OI}\)中能多一些这样的题目就太好了. 题意: 有一个二维的三角坐标系,大概如图所示(图是从atcoder里偷下来的): 坐标系上的每个 ...
- Maven依赖中的scope详解
scope的分类 compile 默认就是compile,什么都不配置也就是意味着compile.compile表示被依赖项目需要参与当前项目的编译,当然后续的测试,运行周期也参与其中,是一个比较强的 ...
- MT【17】利用柯西不等式求三角的最大值
评:此题也可以设$1+cos\theta=t$,平方后变成$t$的单变量利用均值去做. 柯西平衡系数法其实就是待定系数法,利用等号取到的条件.
- 【POI每日题解 #8】DYN-Dynamite
你问蒟蒻为什么一天写两篇每日题解? 难道每日坚果你不能一天吃两包吗? 题目链接 哇…这道题第一反应就是二分答案[太明显了 枚举答案 就那个“关键节点到这些点中距离的最小值的最大值”[蒟蒻读了好几遍…… ...
- 洛谷P4768 [NOI2018]归程(可持久化并查集,最短路)
闲话 一个蒟蒻,在网络同步赛上进行了这样的表演-- T2组合计数不会,T3字符串数据结构不会,于是爆肝T1 一开始以为整个地图都有车,然后写了2h+的树套树,终于发现样例过不去 然后写可持久化并查集D ...