• pat1070. Mooncake (25)


    1070. Mooncake (25)

    时间限制
    100 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region's culture. Now given the inventory amounts and the prices of all kinds of the mooncakes, together with the maximum total demand of the market, you are supposed to tell the maximum profit that can be made.

    Note: partial inventory storage can be taken. The sample shows the following situation: given three kinds of mooncakes with inventory amounts being 180, 150, and 100 thousand tons, and the prices being 7.5, 7.2, and 4.5 billion yuans. If the market demand can be at most 200 thousand tons, the best we can do is to sell 150 thousand tons of the second kind of mooncake, and 50 thousand tons of the third kind. Hence the total profit is 7.2 + 4.5/2 = 9.45 (billion yuans).

    Input Specification:

    Each input file contains one test case. For each case, the first line contains 2 positive integers N (<=1000), the number of different kinds of mooncakes, and D (<=500 thousand tons), the maximum total demand of the market. Then the second line gives the positive inventory amounts (in thousand tons), and the third line gives the positive prices (in billion yuans) of N kinds of mooncakes. All the numbers in a line are separated by a space.

    Output Specification:

    For each test case, print the maximum profit (in billion yuans) in one line, accurate up to 2 decimal places.

    Sample Input:
    3 200
    180 150 100
    7.5 7.2 4.5
    
    Sample Output:
    9.45
    

    提交代码

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<stack>
     6 #include<set>
     7 #include<map>
     8 #include<cmath>
     9 using namespace std;
    10 #define exp 1e-8
    11 struct mooncake{
    12     double amount,price;
    13 };
    14 bool cmp(mooncake a,mooncake b){
    15     return (a.price/a.amount)>(b.price/b.amount);
    16 }
    17 mooncake cake[1005];
    18 int main(){
    19     //freopen("D:\INPUT.txt","r",stdin);
    20     int n,D;
    21     scanf("%d %d",&n,&D);
    22     int i;
    23     for(i=0;i<n;i++){
    24         scanf("%lf",&cake[i].amount);
    25     }
    26     for(i=0;i<n;i++){
    27         scanf("%lf",&cake[i].price);
    28     }
    29     double profit=0;
    30     sort(cake,cake+n,cmp);
    31     /*for(i=0;i<n;i++){
    32         printf("%lf %lf
    ",cake[i].amount,cake[i].price);
    33     }*/
    34     for(i=0;i<n;i++){
    35         if(cake[i].amount<=D){
    36             D-=cake[i].amount;
    37             profit+=cake[i].price;
    38         }
    39         else{
    40             profit+=cake[i].price/cake[i].amount*D;
    41             break;
    42         }
    43         //cout<<profit<<"  "<<D<<endl;
    44     }
    45     printf("%.2lf
    ",profit);
    46     return 0;
    47 }
  • 相关阅读:
    整数转换成字符
    html总结(一)
    ssh服务
    原码反码补码图形化注意
    关于副本机制
    win8设置自动关机
    python制作的翻译器基于爬取百度翻译【笔记思路】
    python多线程扫描爆破网站服务器思路【笔记】
    用python实现多线程爬取影视网站全部视频方法【笔记】
    利用Python3的requests和re库爬取猫眼电影笔记
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4780329.html
Copyright © 2020-2023  润新知