I - The lazy programmer 贪心+优先队列
来源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 贪心+优先队列的更多相关文章
- 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 ...
- poj2970 The lazy programmer 【优先队列】
A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is ...
- POJ 2970 The lazy programmer
The lazy programmer Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2785 Accepted: 70 ...
- hihoCoder 1309:任务分配 贪心 优先队列
#1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN, ...
- UVA 11134 - Fabled Rooks(贪心+优先队列)
We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrict ...
- 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 ...
- HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解
思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...
- 贪心+优先队列 HDOJ 5360 Hiking
题目传送门 /* 题意:求邀请顺序使得去爬山的人最多,每个人有去的条件 贪心+优先队列:首先按照l和r从小到大排序,每一次将当前人数相同的被邀请者入队,那么只要能当前人数比最多人数条件小,该人能 被邀 ...
随机推荐
- 问题8:手机端实现点击按钮时更换颜色(解决IOS不显示背景)
CSS: .sval:active, .sval:focus{ background: #999;color:#fff;opacity:50; } 在触屏上,:hover和:active也不是直接就起 ...
- 我所知道的JS调试
前言 任何一门语言都有对应的调试方法,也有对应的调试工具,JavaScript当然也不例外.最常用的莫过于浏览器这个调试工具了.而今天我们要讲的对于这个基础调试就不细说,我会将目前所有调试javasc ...
- Unity游戏开发图片纹理压缩方案
Unity3D引擎对纹理的处理是智能的:不论你放入的是PNG,PSD还是TGA,它们都会被自动转换成Unity自己的Texture2D格式. 在Texture2D的设置选项中,你可以针对不同的平台,设 ...
- golang 对slice的深拷贝 copy
测试 slice的地址 copy的时候 发现有问题: package main import "fmt" func main() { nums:=[]int{1,2,3,4,5} ...
- Mysql查询特定值是哪些表哪些字段
摘自网上 -- 查询整个数据库中某个特定值所在的表和字段的方法 # flush tables; -- 创建表来存储查询结果 drop table if exists tmp_table; CREATE ...
- flink 有状态udf 引起血案一
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/rlnLo2pNEfx9c/article/details/83422587 场景 近期在做一个画像的 ...
- Java虚拟机垃圾回收:内存分配与回收策略 方法区垃圾回收 以及 JVM垃圾回收的调优方法
在<Java对象在Java虚拟机中的创建过程>了解到对象创建的内存分配,在<Java内存区域 JVM运行时数据区>中了解到各数据区有些什么特点.以及相关参数的调整,在<J ...
- 单片机成长之路(51基础篇) - 006 在Linux下搭建51单片机的开发烧写环境
在Linux下没有像keli那样好用的IDE来开发51单片机,开发环境只能自己搭建了. 第一步:安装交叉编译工具 a) 安装SDCC sudo apt-get install sdcc b)测试SDC ...
- (转)创建Windows服务(Windows Services)N种方式总结
转自:http://www.cnblogs.com/aierong/archive/2012/05/28/2521409.html 最近由于工作需要,写了一些windows服务程序,有一些经验,我现在 ...
- 关于VMware Linux 虚拟机忘记root 密码找回
因为昨天新安装过虚拟机设置了新的密码,再加上我好长时间没有用自己旧的虚拟机,导致忘记了密码,原来虽然知道在单用模式下,找回密码,但是确实是自己从来都没有做过,还好我们组大手飞翔哥告诉了我,怎么找回ro ...