1070. Mooncake (25)
来源:互联网 发布:acii转换为hex单片机 编辑:程序博客网 时间:2024/05/29 08:44
- 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
实质上是部分背包问题。有个需要注意的点,数量是以百万位单位的,所以不一定是整数,不能定义为int。
#include<iostream>#include<algorithm>#include<vector>using namespace std;struct node{ float num; float singprice; float price; node(){} void get() { cin>>price; singprice=price/num; }};bool cmp(node a,node b){ return a.singprice>b.singprice;}int main(){ //freopen("in.txt","r",stdin); int n,m; cin>>n>>m; vector<node> b(n); for(int i=0;i<n;i++) cin>>b[i].num; for(int i=0;i<n;i++) { b[i].get(); } sort(b.begin(),b.end(),cmp); float profit=0; for(int i=0;i<n&&m>0;i++) { if(m>=b[i].num) { profit+=(b[i].num*1.0)*b[i].singprice; m-=b[i].num;; } else { profit+=(m*1.0)*b[i].singprice; break; } } printf("%.2f",profit); system("pause"); return 0;}
- 【PAT】1070. Mooncake (25)
- 1070. Mooncake (25)
- 1070. Mooncake (25)
- 1070. Mooncake (25)
- 1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- 1070. Mooncake (25)
- 1070. Mooncake (25)
- 1070. Mooncake (25)
- 1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- pat 1070. Mooncake (25)
- 1070. Mooncake (25)
- 1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- 1070. Mooncake (25)
- 1070. Mooncake (25)
- 让我细细捋一捋原码反码补码以及计算机中负数的表示
- 会话cookie,session
- 深入理解Android之Gradle
- 学习HTML5-标签
- shell openssl
- 1070. Mooncake (25)
- Gray Code
- Android使用gradle不同配置多项目打包(升级版)
- 数据驱动安全:数据安全分析、可视化和仪表盘——互动出版网
- IIRF简单应用
- Testlink导出报告
- 通告:HTML5自由者博客搬家说明
- 查看support-v4包的源码
- 源码:奇偶数判断