A1070. Mooncake
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
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct{
double amount;
double price;
double per;
}info;
bool cmp(info a, info b){
return a.per > b.per;
}
info cake[];
int main(){
int N;
double D;
scanf("%d%lf", &N, &D);
double ans = ;
for(int i = ; i < N; i++)
scanf("%lf", &cake[i].amount);
for(int i = ; i < N; i++){
scanf("%lf", &cake[i].price);
cake[i].per = cake[i].price / cake[i].amount;
}
sort(cake, cake + N, cmp);
for(int i = ; i < N; i++){
if(D >= cake[i].amount){
ans += cake[i].price;
D = D - cake[i].amount;
}else{
ans += D * cake[i].per;
break;
}
}
printf("%.2f", ans);
cin >> N;
return ;
}
总结:1、贪心策略即可。但有一点,为了稳妥最好把月饼库存、需求、价格等全部用double。之前用int 存储库存,发现有一个测试点怎么都过不去。
A1070. Mooncake的更多相关文章
- PAT甲级——A1070 Mooncake
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- A1070 Mooncake (25 分)
一.参考代码 #include<cstdio> #include<algorithm> #include<iostream> using namespace std ...
- PAT_A1070#Mooncake
Source: PAT A1070 Mooncake (25 分) Description: Mooncake is a Chinese bakery product traditionally ea ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
- 1070 Mooncake (25 分)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn ...
- HDU 4122 Alice's mooncake shop 单调队列优化dp
Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- Mooncake (排序+贪心)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- PAT 1070. Mooncake (25)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- hdu 4122 Alice's mooncake shop(单调队列)
题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...
随机推荐
- Centos下SVN环境部署记录
大多数情况下,我们日常工作中用的版本控制系统都会选择分布式的Git,它相比于集中式的SVN有很多优势.但是有些项目软件基于自身限制,可能只支持SVN做工程同步.废话就不多说了,下面记录下SVN的部署和 ...
- Python_初识函数和返回值_22
#len s = '金老板小护士' len(s) def my_len(): #自定义函数 i = 0 for k in s: i += 1 print(i) length = my_len() pr ...
- vue路由\导航刷新后:ative\localStorage\url截取参数
<el-menu :default-active="$route.path" router mode="horizontal"> <el-me ...
- 《Linux内核设计》第17章学习笔记
- 《Linux内核分析》课程第七周学习总结
姓名:何伟钦 学号:20135223 ( *原创作品转载请注明出处*) ( 学习课程:<Linux内核分析>MOOC课程http://mooc.study.163.com/course/U ...
- 软件项目第一次sprint评论
软件项目第一次sprint评论 组名:天线宝宝四人组 姓名:高长志 1. 组名:9-652组 项目:炸弹人游戏 对于炸弹人游戏,首先 ...
- 实训十二(stick的设定)
上篇我们介绍到人物主角的设定,其实人物是有工具使的,那就是——stick小棍. 信息的获取.起始位置.长度的加载.边界的判断.位置.长度重置是需要我们主要考虑的问题 信息获取上考虑的使什么时候加载st ...
- C#JSON与XML转换
C#JSON转XML 输入:[{\'name\': \'yancy\',\'value\': \'0\'},{\'name\': \'jieny\',\'value\': \'1\'}] string ...
- 『编程题全队』"Gugua"事务管理系统项目宣传文案
一.项目简介 1.项目简介 Gugua是为了解决有事务管理需要的人群的痛苦, 他们需要 一个便利和高效的个人和团体事务管理平台,但是现有的方案并没有很好地解决这些需求,我们有独特的办法是提供跨平台的软 ...
- HDU 2081 手机短号
Problem Description 大家都知道,手机号是一个11位长的数字串,同时,作为学生,还可以申请加入校园网,如果加入成功,你将另外拥有一个短号.假设所有的短号都是是 6+手机号的后5位,比 ...