一共有n个任务,每个任务有一个截止时间di,有一个耗费时间bi ,如果花费x元钱,可以将耗费时间减少为bi-ai*x现在要我们求出一个安排,用最少的前,在截止日期前完成所有任务。
将每一个任务按照截止日期排序
然后用一个结构保存 bi(任务当前耗费时间动态维护) ai 减少比例
每次按照顺序防如优先队列,如果当前时间超过截止日期,则从堆定取出a最大的任务,减少该任务时间,直到当前时间不超过截止时间,如果中途从队列中取出的任务b已经为0则下次不再入队。
417. The lazy programmerProblem code: LAZYPROG |
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 influence other contracts. This 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
First line of the input contains an integer t (1 ≤ t ≤ 45), equal to the number of testcases. Then descriptions of t testcases follow.
First line of description contains the number of contracts N (1 ≤ N ≤ 100000, integer). Each of the next Nlines describes one contract and contains integer numbers ai, bi, di (1 ≤ ai, bi ≤ 10000; 1 ≤ di ≤1000000000) separated by spaces.
At least 90% of testcases will have 1 ≤ N ≤ 10000.
Output
For each testcase in the input your program should output one line with a single real number S. Here 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.
Example
Input: 1 2 20 50 100 10 100 50 Output: 5.00
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 101000
struct node
{
int b,a;
bool operator < (const node &x)const
{
return a<x.a;
}
};
struct data
{
int a,b,d;
bool operator < (const data&a)const
{
return d<a.d;
}
}pro[MAXN];
priority_queue<node> q;
double ans;
int times;
int n;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
while(!q.empty()) q.pop();
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d%d",&pro[i].a,&pro[i].b,&pro[i].d);
sort(pro,pro+n);
node tmp;
ans=0,times=0;
for(int i=0;i<n;i++)
{
tmp.b=pro[i].b;
tmp.a=pro[i].a;
q.push(tmp);
times+=pro[i].b;
if(times>pro[i].d)
{
while(!q.empty()&×>pro[i].d)
{
tmp=q.top();
q.pop();
int dis=min(times-pro[i].d,tmp.b);
times-=dis;
tmp.b-=dis;
if(tmp.b!=0)
q.push(tmp);
ans=ans+dis*1.0/tmp.a;
}
}
}
printf("%.2lf\n",ans);
}
return 0;
}