1070 Mooncake (25 分)
作者:互联网
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 /** 2 * Copyright(c) 3 * All rights reserved. 4 * Author : Mered1th 5 * Date : 2019-02-25-21.32.50 6 * Description : A1070 7 */ 8 #include<cstdio> 9 #include<cstring> 10 #include<iostream> 11 #include<cmath> 12 #include<algorithm> 13 #include<string> 14 #include<unordered_set> 15 #include<map> 16 #include<vector> 17 #include<set> 18 using namespace std; 19 const int maxn=1010; 20 struct Node{ 21 double amounts; 22 double sell; 23 double price; 24 }node[maxn]; 25 bool cmp(Node a,Node b){ 26 return a.price>b.price; 27 } 28 int main(){ 29 #ifdef ONLINE_JUDGE 30 #else 31 freopen("1.txt", "r", stdin); 32 #endif 33 int n; 34 double d; 35 cin>>n>>d; 36 for(int i=0;i<n;i++){ 37 cin>>node[i].amounts; 38 } 39 for(int i=0;i<n;i++){ 40 cin>>node[i].sell; 41 node[i].price=node[i].sell/node[i].amounts; 42 } 43 sort(node,node+n,cmp); 44 double sum=0.0; 45 for(int i=0;i<n;i++){ 46 if(node[i].amounts<d){ 47 sum+=node[i].sell; 48 d-=node[i].amounts; 49 } 50 else{ 51 sum+=node[i].price*d; 52 break; 53 } 54 } 55 printf("%.2f",sum); 56 return 0; 57 }
标签:node,25,int,thousand,1070,amounts,tons,Mooncake,include 来源: https://www.cnblogs.com/Mered1th/p/10433724.html