ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

(hdu step 1.3.1)FatMouse' Trade(ÔÚÊÕÈëÐèÒªÒ»¶¨µÄ¸¶³öµÄÇé¿öÏÂÇó×î´óÊÕÈë)
2015-07-20 17:22:58 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:1´Î
Tags£ºhdu step 1.3.1 FatMouse' Trade ÊÕÈë ÐèÒª Ò»¶¨ ¸¶³ö Çé¿ö ×î´ó

ÌâÄ¿£º


FatMouse' Trade

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5092 Accepted Submission(s): 1530
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 of 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 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
Sample Output
13.333
31.500
AuthorCHEN, Yue
SourceZJCPC2004
RecommendJGShining


ÌâÄ¿´óÒ⣺

ÀÏÊó×¼±¸ÁËM°õèʳ£¬×¼±¸ÄÃÕâЩèʳ¸úè½»»»×Ô¼ºÏ²»¶µÄʳÎï¡£ÓÐN¸ö·¿¼ä£¬Ã¿¸ö·¿¼äÀïÃæ¶¼ÓÐʳÎï¡£Äã¿ÉÒԵõ½J[i]µ«ÄãÐèÒª¸¶³öF[i]µÄèʳ¡£ÒªÄã¼ÆËãÄãÓÐM°õèʳ¿ÉÒÔ»ñµÃ×î¶àʳÎïµÄÖØÁ¿¡£¶øÇÒÕâÀï¿ÉÒÔ²»±ØÃ¿Ò»×鶼ȫ»»£¬¿ÉÒÔ°´±ÈÀý»»¡£¡£¡£ÀýÈç×îºóÄãֻʣ5¿éǮèʳ¡£µ«ÊÇĿǰµÄÒ»¸öÑ¡ÔñÊÇ»°10¿éèʳ¾ÍÄÜ»»È¡6¸öÁ¸Ê³¡£ÄÇôÕâʱºòÄãÓÃ5¿éèʳ¾ÍÄÜ»»È¡3¸öÁ¸Ê³



ÌâÄ¿·ÖÎö£º

ÕâÊÇÒ»µÀ¼òµ¥µÄ̰ÐÄÌâ¡£¶ÔÓÚÕâÖÖ»ñµÃÊÕÈëµÄͬʱÐèÒª¸¶³öһЩµÄÇé¿öÏ£¬¼ÆËã×î´óÊÕÈë¡£ÕâÖÖÌâÒ»°ãÊǸù¾Ý

ÊÕÈëºÍ¸¶³öµÄ±ÈÀýÀ´ÅÅÒ»ÏÂÐò¡£È»ºó¸ù¾ÝÕâ¸ö±ÈÀý´Ó¸ßµ½µÍ½øÐÐÑ¡Ôñ




´úÂëÈçÏ£º

/*
 * a.cpp
 *
 *  Created on: 2015Äê1ÔÂ28ÈÕ
 *      Author: Administrator
 */

#include 
  
   
#include 
   
     #include 
    
      using namespace std; const int maxn = 10005; struct W { double get;//ÊÕÈë double pay;//¸¶³öµÄèʳ double ave;//ÊÕÈë/¸¶³ö±È } w[maxn]; bool cmp(W a, W b) { if (a.ave > b.ave) { return true; } return false; } int main() { int n; double m; while (scanf("%lf%d", &m, &n), n != -1 && m != -1) { int i; for (i = 0; i < n; ++i) { scanf("%lf %lf", &w[i].get, &w[i].pay); w[i].ave = w[i].get / w[i].pay; } sort(w, w + n, cmp);//̰ÐÄ,¶Ôw°´ÕÕget/pay½øÐнµÐòÅÅÐò double sum = 0; i = 0; // while(m >= 0){//²»ÖªµÀΪʲôÕâÖÖд·¨¾ÍÊDz»ÐÐ. // if (m >= w[i].pay) { // sum = sum + w[i].get; // m = m - w[i].pay; // } else { // sum = sum + w[i].ave * m; // break; // } // i++; // } for (i = 0; i <= n - 1; i++) { if (m >= w[i].pay) {//Èç¹ûµ±Ç°Ê£ÓàµÄèʳ»¹×ã¹»µÄ»° sum = sum + w[i].get;//ÄǾͰÑÄǸö·¿¼äµÄÁ¸Ê³È«²¿ÂòÏ m = m - w[i].pay;//²¢ÇÒÊÖÉϼûÈ¥ÏàÓ¦µÄèʳ } else {//Èç¹ûÏÖÔÚÊÖÉϵÄèʳÒѾ­²»¹» sum = sum + w[i].ave * m;//ÄÇô¾Í°´±ÈÀýÄÃÈ¥Ò»¶¨µÄèʳ break; } } printf("%.3lf\n", sum); } return 0; } 
    
   
  



¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºpoj1113--Wall(͹°ü) ÏÂһƪ£ºBZOJ 2339 HNOI2011 ¿¨Å© ×éºÏÊýѧ

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Spring Boot Java£º (2025-12-26 16:20:19)
¡¤Spring Boot¤ÇHello (2025-12-26 16:20:15)
¡¤Spring ¤Î»ù±¾¤«¤éŒ (2025-12-26 16:20:12)
¡¤C++Ä£°å (template) (2025-12-26 15:49:49)
¡¤C ÓïÑÔÖÐÄ£°åµÄ¼¸ÖÖ (2025-12-26 15:49:47)