PAT (Advanced Level) Practise 1070 Mooncake (25)
来源:互联网 发布:手机做淘宝客怎么做 编辑:程序博客网 时间:2024/05/16 11:05
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 200180 150 1007.5 7.2 4.5Sample Output:
9.45
题意:给你n种月饼的数量和价钱,告诉你月饼的总需求,问最多获利多少
解题思路:根据每种月饼的价钱和数量的比值进行排序
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <stack>#include <cmath>#include <map>#include <bitset>#include <set>#include <vector>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;int n;double d;struct node{ double a,p;}x[1005];bool cmp(node x,node y){ return x.p*y.a>y.p*x.a;}int main(){ while(~scanf("%d%lf",&n,&d)) { for(int i=1;i<=n;i++) scanf("%lf",&x[i].a); for(int i=1;i<=n;i++) scanf("%lf",&x[i].p); sort(x+1,x+1+n,cmp); int k=1; double ans=0; while(d>=x[k].a&&k<=n) {ans+=x[k].p;d-=x[k].a;k++;} if(k<=n&&d) ans+=1.0*x[k].p/x[k].a*d; printf("%.2lf\n",ans); } return 0;}
- PAT (Advanced Level) Practise 1070 Mooncake (25)
- PAT (Advanced Level) Practise 1070 Mooncake (25)
- 1070. Mooncake (25)【贪心】——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1070
- Pat(Advanced Level)Practice--1070(Mooncake)
- 【PAT】【Advanced Level】1070. Mooncake (25)
- [PAT] (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise
- 1029. Median (25) @ PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1032. Sharing (25)
- Head First设计模式笔记(外观模式)
- leetcode-27
- Ubuntu16.04 ext4格式硬盘挂载普通用户权限控制
- 安卓开发技术之持久化技术
- android 切换栏目 SmartTabLayout的使用
- PAT (Advanced Level) Practise 1070 Mooncake (25)
- 彻底弄懂Javascript闭包
- Java中Math类的常用方法
- notifyItemChanged(int position) 引起的返回时RecyclerView页面不自然的跳动
- 关于request.getAttribute()获取值的强转问题
- ipa上传app store的大小限制
- 上周关于任务中遇到的问题小总结
- 设计模式(4)-建造者模式
- DragonBoard 410C中的Fastboot与调试串口注意事项