Link:
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_ problem&problem=967
Type: Greedy
Original title:
Shoemaker has N jobs (orders from customers) which him must make. Shoemaker can work on ' only one ' job in each day. For each ith job, it is known the "Integer Ti" (1<=ti<=1000), the time in, it takes the shoemaker to finish the Jo B. For each day of delay before starting to work for the ith job shoemaker must a pay of Si (fine) 1<=si<=10000 Ts. Your the shoemaker, writing a programm to find the sequence of jobs and minimal total fine.
The Input
The input begins with a single positive integer in a line by itself indicating the number of cases following, each of them as described below. This are followed by a blank line, and there are also a blank line between two consecutive.
The "a" of input contains an integer N (1<=n<=1000). The next N lines each contain two numbers:the time and fine to each task in order.
The Output
For each test case, the output must follow the description below. The outputs of two consecutive cases is separated by a blank line.
You are programm should print the sequence of jobs with minimal fine. Each job should is represented by its number in input. All integers should is placed on only one output line and separated by one space. If multiple solutions are possible, print the "the".
Sample Input
1
4
3 4
1 1000
2 2
5 5
Sample Output
2 1 3 4
The main effect of the topic:
Shoemaker has n shoes to repair, for the first pair of shoes to repair ti days. Customers want their shoes to be repaired first, but there is no way, the shoemaker can only fix a pair of shoes at a time. So for not the first repair shoes, every delay of 1 days, the shoemaker will be corresponding compensation SI block money. Ask for a shoe repair order, so that the final total compensation for the lowest price.
Analysis and Summary:
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
A typical greedy question. The total cost of compensation is related to the number of shoe repair days and the amount of money paid every day. The former is the less days the earlier repair, the latter is the more the more cost of early repair, then comprehensive two conditions, with fine/day to sort it.
Code:
/* uva:10026-shoemaker ' s Problem * result:accept * time:0.008s * author:d_double/#include <cs
Tdio> #include <algorithm> using namespace std;
struct node{int no;
Double day, fine;
Double Price; friend BOOL operator < (const node &a, const node &b) {if (A.price!= b.price) return a.price>b.pric
E
Return a.no<b.no;
}}arr[1005];
int main () {int T, N;
scanf ("%d", &t);
while (t--) {scanf ("%d", &n);
for (int i=0; i<n; ++i) {arr[i].no = i+1;
scanf ("%lf%lf", &arr[i].day, &arr[i].fine);
Arr[i].price = Arr[i].fine/arr[i].day;
Sort (arr, arr+n);
for (int i=0; i<n; ++i) if (i) printf ("%d", arr[i].no);
else printf ("%d", arr[i].no);
printf ("\ n");
if (T) printf ("\ n");
return 0; }
Author: csdn Blog shuangde800