pat1070. Mooncake (25)

來源:互聯網
上載者:User

標籤:

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 200180 150 1007.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-811 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\n",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\n",profit);46     return 0;47 }

 

pat1070. Mooncake (25)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.