HDU Saving HDU (greedy)

Source: Internet
Author: User

Saving HDU time limit:3000/1000ms (java/other) Memory limit:32768/32768k (Java/other) total submission (s): Acce pted Submission (s): 26font:times New Roman | Verdana | Georgia Font Size:←→problem Description said the last talk about the sea East group face strife, the company's elder is only left Xhd couple two people. Obviously, as a businessman who has worked hard for years, XHD will not sit idly by.
One day, when he was thinking about the remedy, suddenly thought of his family heirloom, that is the company set up, the father as a gift to send a brocade bag, Xu father at that time, not to the last resort, do not open it. "Now is not the time to do it most?" , while thinking, XHD side found this careful custody of the brocade bag, open a look, inside only a word "Hangzhou North foot thousand people hole has treasure".
Apart, Xhd pick up a big pocket on the start, this thousand man hole he is know, small time, dad once brought him to this secluded intersection, and told him, this is thousand man hole. He now understood the meaning of his father's words.
Despite a little impression, Xhd still spent a lot of energy to find this unusual hidden hole, into a look, almost stunned, really is dazzling! But despite the variety of baby, but the amount of each treasure is not much, of course, each of the baby unit volume of the price is not the same, in order to save HDU, now please help to calculate as soon as possible XHD can bring back how much value of the baby? (assuming that the baby can be split, the value of the split is proportional to the corresponding volume)
Input inputs contain multiple test instances, the first line of each instance being two integers V and n (v,n<100), each representing the capacity of the pocket and the kind of baby, followed by n rows each containing 2 integer pi and mi (0<pi,mi<10), Indicates the unit price and the corresponding volume of a baby, and V is 0 to end the input.
Output for each test instance, print out how much value XHD can fetch, with the output of each instance on one line.
Sample Input
2 23 12 30
Sample Output
5 after the HDU, will the crisis be out of the bag? To know the funeral, and listen to tell--
Authorlcy SOURCEACM Program Design _ Final Exam (time has been set!!) ) AC Code:
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio>using namespace std;struct jewelry{    int num,value;    double ratio;}; Jewelry My[111];bool Comp (jewelry a,jewelry b) {    return a.value>b.value;} int main () {    int v,n;    while (CIN>>V>>N&&V) {        int i,j;        for (i=0;i<n;++i) {            cin>>my[i].value>>my[i].num;        }        Sort (my,my+n,comp);        for (i=0;i<n;++i) cout<<my[i].value<< ' <<my[i].num<< ' \12 ';        int sum=0,k=0;        for (I=0;i<n;++i) {for            (j=1;j<=my[i].num;++j) {                if (k+1<=v) {                    k++;                    Sum+=my[i].value        ;        }}} cout<<sum<< ' \12 ';    }    return 0;}


HDU Saving HDU (greedy)

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.