POJ 2970 The lazy programmer(优先队列+贪心)
Language:
Default
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 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 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 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 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 Sample Input 2 Sample Output 5.00 Source
Northeastern Europe 2004, Western Subregion
|
/* 题意:有n个任务要完毕,每一个任务有属性 a,b,d
分别代表 额外工资,完毕时间,结束时间。
假设不给钱。那么完毕时间为b,给x的额外工资,那么完毕时间b变成 b-a*x 求在全部任务在各自最后期限前完毕所须要给的最少的钱 思路:先把任务依照结束之间排序,然后依次完毕每一个任务,假设这个任务无法完毕
那么在前面(包含这个)任务中找到a属性最大的任务(能够再给他钱的前提),
给钱这个腾出时间来完毕当前这个任务,而这个能够用优先队列维护 */ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map> #define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1) #define eps 1e-8
typedef __int64 ll; #define fre(i,a,b) for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define ssf(n) scanf("%s", n)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define bug pf("Hi\n") using namespace std; #define INF 0x3f3f3f3f
#define N 100005 struct stud{
int a,b,d;
double money;
bool operator<(const stud b) const
{
return a<b.a;
} }f[N]; int cmp(stud x,stud y)
{
return x.d<y.d;
} priority_queue<stud>q; int n; int main()
{
int i,j;
while(~scanf("%d",&n))
{
for(i=0;i<n;i++)
{
scanf("%d%d%d",&f[i].a,&f[i].b,&f[i].d);
f[i].money=0; //已经给这个任务的钱
}
sort(f,f+n,cmp); while(!q.empty()) q.pop();
double ans,day;
ans=day=0;
stud cur;
for(i=0;i<n;i++)
{
q.push(f[i]);
day+=f[i].b;
while(day>f[i].d)
{
cur=q.top();
q.pop();
double temp=(double)(day-f[i].d)/cur.a; //完毕这个任务须要给cur任务的钱
if(temp+cur.money<(double)cur.b/cur.a) //假设这个钱加上已经给的钱小于能够给他的钱
{
day-=temp*cur.a;
cur.money+=temp;
ans+=temp;
q.push(cur);
break;
}
else
{
temp=((double)cur.b/cur.a-cur.money);
day-=temp*cur.a;
ans+=temp;
}
}
} printf("%.2f\n",ans);
}
return 0;
}
Language:
Default
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 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 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 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 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 Sample Input 2 Sample Output 5.00 Source
Northeastern Europe 2004, Western Subregion
|
POJ 2970 The lazy programmer(优先队列+贪心)的更多相关文章
- POJ 2970 The lazy programmer
The lazy programmer Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2785 Accepted: 70 ...
- POJ 2970 The lazy programmer(贪心+单调优先队列)
A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is ...
- POJ 3253 Fence Repair (优先队列)
POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the past ...
- poj 3614 奶牛美容问题 优先队列
题意:每头奶牛需要涂抹防晒霜,其中有效的范围 min~max ,现在有L种防晒霜,每种防晒霜的指数为 f 瓶数为 l,问多少只奶牛可以涂上合适的防晒霜?思路: 优先队列+贪心 当奶牛的 min< ...
- 最高的奖励 - 优先队列&贪心 / 并查集
题目地址:http://www.51cpc.com/web/problem.php?id=1587 Summarize: 优先队列&贪心: 1. 按价值最高排序,价值相同则按完成时间越晚为先: ...
- POJ2431 优先队列+贪心 - biaobiao88
以下代码可对结构体数组中的元素进行排序,也差不多算是一个小小的模板了吧 #include<iostream> #include<algorithm> using namespa ...
- hdu3438 Buy and Resell(优先队列+贪心)
Buy and Resell Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 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 ...
随机推荐
- LoadRunner error -27498
URL=http://172.18.20.70:7001/workflow/bjtel/leasedline/ querystat/ subOrderQuery.do错误分析:这种错误常常是因为并发压 ...
- 指定URL,计算文件大小
将http://www.baidu.com替换成指定的URL,就可以获得文件的大小. 文件大小已经转换为以KB为单位. url对象用openconnection()打开连接:获得URLConnecti ...
- 数往知来 HTML<十一>
HTML_CSS <!--一.表单 <form></form> 表单就是用来进行数据提交的标签 表单就是一对<form></form>标 ...
- SparkR grammer
They are different between local R and sparkR: sparkR 跑通的函数: http://blog.csdn.net/wa2003/article/det ...
- 哈希(Hash)与加密(Encrypt)的基本原理、区别及工程应用
0.摘要 今天看到吉日嘎拉的一篇关于管理软件中信息加密和安全的文章,感觉非常有实际意义.文中作者从实践经验出发,讨论了信息管理软件中如何通过哈希和加密进行数据保护.但是从文章评论中也可以看出很多朋友对 ...
- Raspberry Pi上手
2013-05-21 买的树莓派终于到手了,嘿嘿.我在官方代理ICKEY买的,是英国版,B型. 上手教程可以根据Getting Started with Raspberry Pi(网上有电子版免费下载 ...
- 20151227感知机(perceptron)
1 感知机 1.1 感知机定义 感知机是一个二分类的线性分类模型,其生成一个分离超平面将实例的特征向量,输出为+1,-1.导入基于误分类的损失函数,利用梯度下降法对损失函数极小化,从而求得此超平面,该 ...
- 总结调用Flash的几种方法
一.Adobe 提供的方法 <object width="200" height="200" classid="clsid:D27CDB6E-A ...
- POJ-2785 4 Values whose Sum is 0(折半枚举 sort + 二分)
题目链接:http://poj.org/problem?id=2785 题意是给你4个数列.要从每个数列中各取一个数,使得四个数的sum为0,求出这样的组合的情况个数. 其中一个数列有多个相同的数字时 ...
- window