HDU 1009 Fatmouse ' Trade

Source: Internet
Author: User

Fatmouse ' Trade

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 54549 Accepted Submission (s): 18288


Problem Descriptionfatmouse prepared M pounds of cat food, ready-to-trade with the cats guarding the warehouse containing He favorite food, JavaBean.
The warehouse has N rooms. The i-th contains j[i] pounds of JavaBeans and requires f[i] pounds of cat food. Fatmouse does not has the to trade for all the JavaBeans in the the the same, instead, he may get j[i]* a% of pounds JavaBeans if he Pays f[i]* a% pounds of cat food. Here A is a real number. Now he's assigning this homework to you:tell him the maximum amount of JavaBeans he can obtain.

Inputthe input consists of multiple test cases. Each test case is begins with a line containing the non-negative integers M and N. Then N lines follow, each contains, non-negative integers j[i] and f[i] respectively. The last test case was followed by Two-1 ' s. All integers is not greater than 1000.

Outputfor each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum Amoun T of JavaBeans that Fatmouse can obtain.

Sample INPUT5 37 24 35 220 325 1824 1515 10-1-1

Sample Output13.33331.500

Authorchen, Yue

SourceZJCPC2004

recommendjgshining | We have the carefully selected several similar problems for you:1051 1052 1007 1006 10,531-way base greedy, just sort it out, apply the sort sort and structure body, feel very square and strong. Test instructions: Mice prepared m-pound cat food, ready to take these cat food and cats to exchange their favorite food. There are n rooms, and there is food in every room. You can get j[i] but you need to pay f[i] cat food. You have to calculate the weight of the most food you can get with M-pound cat food. Food can be divided. Attached code:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 structnode7 {8     intb;9     DoubleC;Ten}ss[1005]; One BOOLCMP (node X,node y) A { -     returnX.c>y.c; - } the intMain () - { -     intn,m,i,j,k,w; -     Doubles; +      while(cin>>n>>m) -     { +         if(n==-1&&m==-1) A          Break; ats=0; -          for(i=0; i<m;i++) -         { -Cin>>ss[i].a>>ss[i].b; -Ss[i].c= (Double) ss[i].a/(Double) ss[i].b;//cost-effective, every dollar can change how much this food -         } inSort (ss,ss+m,cmp);//by Price-to-value size, the more price to buy, the higher the cost -          for(i=0; i<m;i++) to         { +             if(N&GT;=SS[I].B)//have more money than the whole price of the food -             { theS+=SS[I].A;//the weight of all food *n-=ss[i].b;//minus the money spent. $             }Panax Notoginseng             Else   //if not enough to buy all this food -             { theS+=ss[i].c*n;//spend all the money to buy this food +                  Break;//money is 0, jump out of the loop A             } the         } +printf"%.3lf\n", s);//Save 3-bit decimal output -     } $     return 0; $}

HDU 1009 Fatmouse ' Trade

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.