zoukankan      html  css  js  c++  java
  • HDU1009--FatMouse' Trade

    FatMouse' Trade
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 33038 Accepted Submission(s): 10693


    Problem Description
    FatMouse 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.


    Input
    The 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.


    Output
    For 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


    Author
    CHEN, Yue


    Source
    ZJCPC2004


    Recommend
    JGShining

     1 #include<cstdio> 
     2 #include<cmath> 
     3 #include<iostream> 
     4 #include<algorithm> 
     5 #include<cstring> 
     6 using namespace std; 
     7     
     8 struct node 
     9 { 
    10     int ja,va; 
    11     double sor; 
    12 }edge[10001]; 
    13     
    14 bool cmp(node a,node b) 
    15 { 
    16     return a.sor<b.sor; 
    17 } 
    18     
    19 int main() 
    20 { 
    21     int m,n; 
    22     while(scanf("%d%d",&m,&n)!=EOF) 
    23     { 
    24         if(m==-1&&n==-1)break; 
    25         int i; 
    26         for(i=0;i<n;i++) 
    27         { 
    28             scanf("%d%d",&edge[i].ja,&edge[i].va); 
    29             edge[i].sor=edge[i].va*1.0/edge[i].ja; 
    30         } 
    31     
    32         sort(edge,edge+n,cmp); 
    33     
    34         double sum=0; 
    35         for(i=0;i<n;i++) 
    36         { 
    37             if(m>edge[i].va) 
    38             { 
    39                 sum+=edge[i].ja; 
    40                 m-=edge[i].va; 
    41             } 
    42             else
    43             { 
    44                 sum+=m*1.0/edge[i].va*edge[i].ja; 
    45                 break; 
    46             } 
    47         } 
    48         printf("%0.3lf
    ",sum); 
    49     } 
    50     return 0; 
    51 }
    View Code
  • 相关阅读:
    C# 多线程并发锁模式-总结
    C# 7 out variables, tuples & other new features
    AngleSharp 的Dom 选择器
    Html Agility Pack
    javascript判断是否按回车键
    VSTS 免费代码git/tfs托管体验-使用代码云托管
    NPOI 中的公式列的值的获取
    topshelf 开发windows 服务资料
    vue之指令
    hash和md5
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3185221.html
Copyright © 2011-2022 走看看