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): 59851 Accepted Submission (s): 20095


problem DescriptionFatmouse prepared M pounds of cat food, ready-to-trade with the cats guarding the warehouse containing his favorite fo OD, 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. 

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

Sample Input5 PNs 325 1824 1515 10-1-1 

Sample Output13.33331.500 

AuthorCHEN, Yue 

SourceZJCPC2004 

recommendjgshining  use format input and output format specifier%D,%F,%LF, etc., should pay attention to the corresponding relationship with int,float,double and other types.  
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5 Const intmax=1050;6 structroom{7     DoubleJ;8     DoubleF;9     DoubleW;Ten }r[max]; One  A BOOLCompareConst&AMP;R1,Const&R2) - { -     if(r1.w>R2.W) the         return true; -     Else -         return false; - } +  - intMain () + { A     DoubleM,ANS,JV,FV; at     intN; -      while(SCANF ("%lf%d", &m,&n) = =2&&n!=-1) -     { -ans=0; -          for(intI=0; i<n;i++) -         { inscanf"%LF%LF",&jv,&FV); -r[i].j=JV; tor[i].f=FV; +r[i].w=jv/FV; -         } theSort (r,r+n,compare); *  $          for(intI=0; i<n;i++)Panax Notoginseng         { -             if(m>=r[i].f) the             { +m-=r[i].f; Aans+=R[I].J; the              +             } -             Else $             { $ans+=r[i].w*m; -                  Break; -             } the         } -printf"%.3lf\n", ans);Wuyi     } the}

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.