Language:DefaultThe Lazy programmer
Time Limit: 5000MS |
|
Memory Limit: 65536K |
Total Submissions: 1566 |
|
Accepted: 386 |
Description A New Web-design Studio, called SMART (Simply Masters of ART), employs and 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, the studio has already got N contracts for Web site Develo Pment. Each contract have a deadline di . It is known, 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 was very greedy for money. If the director pays him XI dollars Extra, he needs only ( bi ? < Strong>ai xi ) of the time to does his job. But this extra payment does not influent other contract. It means that each contract should is paid separately to being done faster. The programmer is so greedy that he can do his job almost instantly if the extra payment are ( bi ?&nb Sp AI ) Dollars for the contract number I . The director has a difficult problem to solve. He needs to organize programmer's job and, May is, assign extra payments for some of the contracts so it all contracts a Re 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, 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) separated by spaces. Output The output needs to contain a is 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 then the programmer could perform all cont Racts in time. The number must has a digits after the decimal point. Sample Input 220 50 10010) 100 50
Sample Output 5.00
Source Northeastern Europe 2004, Western subregion
|
/* Test Instructions: There are n tasks to complete, each task has attributes a,b,d each representing the extra pay, completion time, and end time. If you do not give the money, then the completion time is B, give X the extra pay, then the completion time B becomes b-a*x the minimum amount of money that needs to be given in order to complete all tasks before their respective deadlines: first sort the tasks by the end, then complete each task sequentially, if the task cannot be completed Then in the previous (including this) task to find the a property of the biggest task (can give him the premise of money), give the money to make time to complete the current task, and this can be used in priority queue Maintenance */#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-8typedef __int64 ll, #define FRE (i,a,b) for (i = A; I <b; i++) #d Efine 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 0x3f 3f3f3f#define N 100005struct 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; The money already given to this task} 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]);d ay+=f[i].b;while (DAY>F[I].D) {cur=q.top (); Q.pop ();d ouble temp= (Double) ( DAY-F[I].D)/cur.a; To complete this task you need to give cur the money for the task if (temp+cur.money< (double) cur.b/cur.a)///If this money plus has given the money less than can give him the money {day-=temp*cur.a;cur.money+= Temp;ans+=temp;q.push (cur); break;} else{temp= (double) Cur.b/cur.a-cur.money;d Ay-=temp*cur.a;ans+=temp;}}} printf ("%.2f\n", ans);} return 0;}
Language:DefaultThe Lazy programmer
Time Limit: 5000MS |
|
Memory Limit: 65536K |
Total Submissions: 1566 |
|
Accepted: 386 |
Description A New Web-design Studio, called SMART (Simply Masters of ART), employs and 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, the studio has already got N contracts for Web site Develo Pment. Each contract have a deadline di . It is known, 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 was very greedy for money. If the director pays him XI dollars Extra, he needs only ( bi ? < Strong>ai xi ) of the time to does his job. But this extra payment does not influent other contract. It means that each contract should is paid separately to being done faster. The programmer is so greedy that he can do his job almost instantly if the extra payment are ( bi ?&nb Sp AI ) Dollars for the contract number I . The director has a difficult problem to solve. He needs to organize programmer's job and, May is, assign extra payments for some of the contracts so it all contracts a Re 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, 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) separated by spaces. Output The output needs to contain a is 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 then the programmer could perform all cont Racts in time. The number must has a digits after the decimal point. Sample Input 220 50 10010) 100 50
Sample Output 5.00
Source Northeastern Europe 2004, Western subregion
|
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 2970 The Lazy programmer (priority queue + greedy)