Fatmouse ' Trade hdu1009

Source: Internet
Author: User

Title Address: http://acm.hdu.edu.cn/showproblem.php?pid=1009

Fatmouse ' Trade

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


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. Kankan prepared M Catty of food, prepared with the House long Exchange philosophy treasure ♂ has N rooms. The first room has j[i] ♂ need to f[i] Jin's food. Kankan can not change the entire room ♂, he can use f[i]* a% food for j[i]* a% ♂ now give you a real number M ask you Kankan how much can get ♂

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 thought: 1 struct structure storage data, 2 by "can use f[i]* a% food for j[i]* a% of ♂", F[i]/j[i] The greater, Kankan from the room for ♂ more,           So use the sort function by F[i]/j[i] from large to small sort, 3 Kankan food is limited, so into the room may change all the ♂, may also press "f[i]* a% food for j[i]* a%" The Law of the ♂ The size of the food and the f[i] of the room should be judged before the Kankan enter the room. The code is as follows:
#include <cstdio>#include<algorithm>using namespacestd;structhuan{Doublej,f; DoubleC;} huan[3005];BOOLCMP (Huan A, Huan B) {returnA.C >B.C;}intMain () {Doublem; intn,t;  while(SCANF ("%lf%d", &m, &n)!=eof && (m!=-1|| n!=-1 ) )    {        intI, j, K; Doublesum=0;  for(i=0; i<n; i++) {scanf ("%LF%LF", &AMP;HUAN[I].J, &huan[i].f); HUAN[I].C= HUAN[I].J/huan[i].f; } sort (Huan, Huan+n, CMP);//sort by F from small to large         for(i=0; i<n; i++)        {            if(M >= huan[i].f)//the whole change.{sum + = HUAN[I].J; M-=huan[i].f; }               Else//The number of rice is not enough to change{sum + = m*huan[i].c; Break; }} printf ("%.3lf\n", sum); }    return 0;}

Fatmouse ' Trade hdu1009

Related Article

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.