来源poj2970

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

20 50 100

10 100 50

Sample Output

5.00

按deadline排序,然后时间不够的,先之前的买,poj输出有问题%.2lf过不了%.2f才行

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+10;
struct test
{
int a,time,dead;
friend bool operator <(test a,test b)
{
return a.a<b.a;
}
}a[N];
bool cmp(test a,test b)
{
return a.dead<b.dead;
}
priority_queue<test>v;
int main()
{
int n;scf(n);
rep(i,0,n)
sf("%d%d%d",&a[i].a,&a[i].time,&a[i].dead);
sort(a,a+n,cmp);
test t;
int now=0;
double money=0.0;
rep(i,0,n)
{
v.push(a[i]);
if(a[i].time+now>a[i].dead)
{
int chaju=a[i].time+now-a[i].dead;
now=a[i].dead;
while(chaju>0)
{
t=v.top();
v.pop();
if(t.time>chaju)
{
money+=1.0*chaju/t.a;
t.time-=chaju;
chaju=0;
v.push(t);
}else
{
money+=1.0*t.time/t.a;
chaju-=t.time;
}
}
}else
now+=a[i].time;
}
pf("%.2f\n",money);
return 0;
}

I - 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. poj2970 The lazy programmer 【优先队列】

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

  4. POJ 2970 The lazy programmer

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

  5. hihoCoder 1309:任务分配 贪心 优先队列

    #1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN,  ...

  6. UVA 11134 - Fabled Rooks(贪心+优先队列)

    We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrict ...

  7. C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列

    C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  8. HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解

    思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...

  9. 贪心+优先队列 HDOJ 5360 Hiking

    题目传送门 /* 题意:求邀请顺序使得去爬山的人最多,每个人有去的条件 贪心+优先队列:首先按照l和r从小到大排序,每一次将当前人数相同的被邀请者入队,那么只要能当前人数比最多人数条件小,该人能 被邀 ...

随机推荐

  1. Aizu2170 Marked Ancestor(并查集)

    https://vjudge.net/problem/Aizu-2170 并查集用于管理元素分组情况. 建树pre[]记录父节点,一开始只有结点1被标记了,所以find()最终得到的根都是1. 如果遇 ...

  2. django之ajax补充

    之前的ajax使用都是依据jquery来使用的,本篇会先分析ajax的原生的js代码实现,还有jsonp的介绍和最终使用. 本篇导航: js实现的ajax 同源策略与Jsonp 一.js实现的ajax ...

  3. mysql sql执行慢 分析过程

    摘自: https://blog.csdn.net/zhuzaijava/article/details/77935200 为了验证select 1 与 select 1 from tableName ...

  4. zookeeper视图工具

    https://www.cnblogs.com/xd502djj/p/8919425.html

  5. linux清除缓存

    linux清除缓存:需要root权限$ sync$ echo 3 >/proc/sys/vm/drop_caches 上面的echo 3 是清理所有缓存 echo 0 是不释放缓存 echo 1 ...

  6. shell符号解释

    #符号详解 () 在子shell中运行 (a=1);echo $a,结果是空,因为a=1不是在当前shell中运行的(a=1);(echo $a)也是空的 小技巧:(cd $path, do some ...

  7. Effective Java 第三版——68. 遵守普遍接受的命名约定

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  8. top 命令

    首先介绍top中一些字段的含义: VIRT:virtual memory usage 虚拟内存1.进程"需要的"虚拟内存大小,包括进程使用的库.代码.数据等 2.假如进程申请100 ...

  9. pm2启动jenkins不存在tty的问题

    问题 使用pm2管理jenkins, 直接启动bash script, 运行一些命令时会遇到tty不存在的错误 child_process.js:120 p.open(fd); ^ Error: EN ...

  10. Hive 根据表中某个字段动态分区 以及临时表创建

    使用hive储存数据时,需要对做分区,如果从kafka接收数据,将每天的数据保存一个分区(按天分区),保存分区时需要根据某个字段做动态分区,而不是傻傻的将数据写到某一个临时目录最后倒入到某一个分区,这 ...