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): 32207 accepted submission (s): 10402

Problem descriptionfatmouse prepared m pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has n rooms. the I-th room contains J [I] pounds of JavaBeans and requires f [I] pounds of cat food. fatmouse does not have to trade for all the JavaBeans in the room, instead, he may get J [I] * A % pounds of JavaBeans if he pays f [I] * A % pounds
Cat food. Here a is a real number. Now he is 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 begins with a line containing two non-negative integers m and n. then n lines follow, each contains two non-negative integers J [I] and f [I] respectively. the last test case
Is followed by two-1's. All integers are 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 amount of JavaBeans that fatmouse can obtain.

Sample Input

 
5 37 24 35 220 325 1824 1515 10-1-1

Sample output

 
13.33331.500

Authorchen, Yue

Sourcezjcpc2004

Recommendjgshining greedy sort by swap ratio. It starts from the exchange ratio.

 # include 
  
    # include 
   
     # include 
    
      using namespace STD; struct Jud {Double J, F, JF;} JD [1010]; int CMP (Jud A, Jud B) {return. jf> B. jf;} int main () {int n, m, I; double MA; while (scanf ("% d", & M, & n )) {If (n =-1 & M =-1) break; for (I = 0; I 
     
       JD [I]. f) MA + = JD [I]. j, M-= JD [I]. f; else {MA + = m * JD [I]. jf; break;} printf ("%. 3lf \ n ", Ma) ;}return 0 ;}
     
    
   
  

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.