UVa 10026-shoemaker ' s problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.