The lazy programmer
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 2785   Accepted: 703

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 aibidi (1 ≤ aibi ≤ 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
20 50 100
10 100 50

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

  1. POJ 2970 The lazy programmer(优先队列+贪心)

    Language: Default The lazy programmer Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 1 ...

  2. POJ 2970 The lazy programmer(贪心+单调优先队列)

    A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is ...

  3. I - The lazy programmer 贪心+优先队列

    来源poj2970 A new web-design studio, called SMART (Simply Masters of ART), employs two people. The fir ...

  4. poj2970 The lazy programmer 【优先队列】

    A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is ...

  5. POJ 1337 A Lazy Worker(区间DP, 背包变形)

    Description There is a worker who may lack the motivation to perform at his peak level of efficiency ...

  6. Keep It Simple

    The KISS principle, or Keep It Simple, Stupid, spans many trades, industries, and professions. The m ...

  7. POJ - 1245 Programmer, Rank Thyself

    POJ - 1245 Programmer, Rank Thyself Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d  ...

  8. poj 3468(线段树+lazy思想)

    题目链接:http://poj.org/problem?id=3468 思路:如果直接去做,每次都更新到叶子节点,那必然会TLE,我们可以采用lazy的思想:没必要每次更新都更新到叶子节点,只要有一个 ...

  9. POJ 3237 Tree (树链剖分 路径剖分 线段树的lazy标记)

    题目链接:http://poj.org/problem?id=3237 一棵有边权的树,有3种操作. 树链剖分+线段树lazy标记.lazy为0表示没更新区间或者区间更新了2的倍数次,1表示为更新,每 ...

随机推荐

  1. Linux列举所有隐藏文件

    ll 命令是 ls -l的缩写 ls -a是列举所有(all)文件,包含隐藏文件,以.开头的文件. ls -l是以列表(list)方式列举文件. http://bbs.chinaunix.net/th ...

  2. SQLite reset password

    https://www.codeproject.com/tips/993395/sqliter-change-set-remove-passwords-on-sqlite-d https://sour ...

  3. php多进程pcntl学习-僵尸进程

    上个月写的文章,php多进程pcntl学习(一)现在发现并不完整,因为虽然提到了关闭子进程,但是并没有回收子进程,简单的说就是当子进程比父进程先退出,而父进程没对其做任何处理的时候,子进程将会变成僵尸 ...

  4. 属性动画总结(Property Animation)

    一.概述 属性动画可以作用在View的属性上,对属性进行修改,而且不要求对应的属性一定是有显示效果的. 二.属性动画的实现方式 1.基础的类Animator Animator是一个抽象类,是属性动画的 ...

  5. jenkins--svn+Email自动触发1(作业设置)

    项目名称设置: svn设置: 触发构建设置: 构建加入sonar-scanner代码扫描: 邮件设置: 邮件触发器配置:

  6. bzoj 2120 数颜色 (带修莫队)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2120 题意:两种操作:Q 询问区间  l - r  内颜色的种类 ,R 单点修改 思路 ...

  7. MT【68】一边柯西一边舍弃

    求$\sqrt{x-5}+\sqrt{24-3x}$的最值. 通常考试时会考你求最大值,常见的方式有三角代换,这里给如下做法: 证明:$\sqrt{x-5}+\sqrt{24-3x}=\sqrt{x- ...

  8. 搜索Ex

    哎呀好几天没写POI题解了 (>﹏<) 看着摇曳不定的小旗子深深惶恐 打算开始肝洛谷试炼场的提高分区了[对我就是这么菜… 搜索Ex 比暴搜不错得多的题 洛谷P1514 引水入城 拆成两问来 ...

  9. Rsync 服务器端配置

    Centos 6.3 已经自带Rsync服务 安装xinetd # yum -y install xinetd 编辑/etc/xinetd.d/rsync文件,把disable = yes修改为dis ...

  10. Leetcode 190.颠倒二进制位 By Python

    颠倒给定的 32 位无符号整数的二进制位. 示例: 输入: 43261596 输出: 964176192 解释: 43261596 的二进制表示形式为 000000101001010000011110 ...