来源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. poj3320 Jessica's Reading Problem(尺取思路+STL)

    https://vjudge.net/problem/POJ-3320 尺取法,要想好组织方式. 又被卡了cin.. #include<iostream> #include<cstd ...

  2. 通过IIS操作修改服务器文件没有权限的解决办法

    问题描述:通过部署在IIS上的程序去操做文件(比如删除.旋转图片等)时,在本地执行没有问题,但是部署到服务器上提示“没有权限”.解决方法:找到你需要操作的文件的根文件夹,右键点击属性 选择“安全”选项 ...

  3. kettle 6.1 按时间增量抽取数据

    1.设计一个增量 配置表ETL_INCREMENTAL,用于配置表的增量时间等数据 2.增量JOB全图如下: 2.1获取增量时间变量,并设置增量变量 2.2 表的增量转换,在表中引用2.1的增量变量 ...

  4. php 通过 create user 和grant 命令无法创建数据库用户和授权的解决办法

    php 通过 create user 和grant 命令无法创建数据库用户和授权的解决办法 解决办法, 通过 insert 命令的方式进行创建. 创建数据库用户: $sql= "insert ...

  5. spring boot swagger-ui.html 404

    很奇怪的问题,找了好久. 因为spring boot+swagger实现起来很简单.看下面三部曲: 1.pom添加两个swagger依赖. <!-- Swagger依赖包 --> < ...

  6. docker安装mongodb并备份

    安装 官方镜像地址: https://hub.docker.com/_/mongo?tab=description 可以查看对应的dockerfile, 通过观察docker-entrypoint.s ...

  7. 小程序longpress的bug及其解决

    我的小程序中,用到一个长按修改的功能,设计是这样的,短按tap,长按longpress 但是,偶尔出现长按无效的情况.我自己都经常碰到,今天仔细研究,用半天时间反复寻找,重现,发现问题和内存或别的因素 ...

  8. 解决Visual Studio调试突然变慢卡死的问题

    最开始摸不到头脑,之前还能好好调试的啊.后来在VS的调试菜单的符号选项里面发现了系统环境变量_NT_SYMBOL_PATH 的值为:srv*c:\symbols*http://msdl.microso ...

  9. linux下 彻底修改python的包/模块导入路径

    python模式下,有时候需要导入  import某些模块或者包.明明这个模块/包是存在的,却提示导入错误,比如,“ImportError: No module named lxml”. 但是当你在命 ...

  10. WordPress <= 4.6 命令执行漏洞(PHPMailer)复现分析

    漏洞信息 WordPress 是一种使用 PHP 语言开发的博客平台,用户可以在支持 PHP 和 MySQL 数据库的服务器上架设属于自己的网站.也可以把 WordPress 当作一个内容管理系统(C ...