Title: A shoemaker receives a lot of tasks, each task has a finish that takes time, and the deferred task will have a fine every day,
Now all tasks have been postponed, asking the minimum amount of fines (only one job per day).
Analysis: Greed. The conversion problem is that if you do not do then the fine amount is days*σ (each task is fined);
And every good one thinks that every day after the start of the day will receive a corresponding fine of the proceeds;
The maximum value of income can be, here by the sex-ratio sort.
Proposition: By the sex-ratio of the ranking to benefit the most.
Proof: Value is p[i], time is c[i];
1. If only two tasks are p[i]/c[i] > P[j]/c[j], p[i]*c[j] > P[j]*c[i], established;
2. If the maximum order of the K tasks is 1~k, then the k+1 task may be inserted in any position, and the position will be behind m;
That is, the new task sequence is: 1~m,k+1,m+1~k, only to prove that the 1~k-1 of the task sequence is the most profitable;
The first M is the same, so simply prove that the task sequence m+1~k+1 yield is greater than k+1,m+1~k, (0≤m≤k);
The m+1~k as a whole, then converted to two tasks, the above has been proved to be established;
3. The proposition is correct in the end.
Description: Note the output format ╮(╯▽╰)╭.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio>using namespace std;typedef struct _dnode{double price;int index;} Dnode;dnode Data[1001];bool CMP (const dnode A, const Dnode b) {return a.price > b.price;} int main () {int n,m,time,fine;while (~scanf ("%d", &n)) while (n--) {scanf ("%d", &m), for (int i = 0; i < m; + + i) {scanf ("%d%d", &time,&fine);d ata[i].price = 1.0*fine/time;data[i].index = i+1;} Sort (data, data+m, CMP), for (int i = 0; i < m; + + i) printf ("%d%c", data[i].index,i==m-1? ' \ n ': '); if (n) puts ("");} return 0;}
UVa 10026-shoemaker ' s problem