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的更多相关文章

  1. PAT甲级——A1070 Mooncake

    Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...

  2. A1070 Mooncake (25 分)

    一.参考代码 #include<cstdio> #include<algorithm> #include<iostream> using namespace std ...

  3. PAT_A1070#Mooncake

    Source: PAT A1070 Mooncake (25 分) Description: Mooncake is a Chinese bakery product traditionally ea ...

  4. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  5. 1070 Mooncake (25 分)

    1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn ...

  6. 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 ...

  7. Mooncake (排序+贪心)

    Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...

  8. PAT 1070. Mooncake (25)

    Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival.  Many types ...

  9. hdu 4122 Alice's mooncake shop(单调队列)

    题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...

随机推荐

  1. [UWP 自定义控件]了解模板化控件(9):UI指南

    1. 使用TemplateSettings统一外观 TemplateSettings提供一组只读属性,用于在新建ControlTemplate时使用这些约定的属性. 譬如,修改HeaderedCont ...

  2. 基于SSH 供应链管理系统质量属性说明

    产品的易用程度如何,执行速度如何,可靠性如何,当发生异常情况时,系统如何处理.这些被称为软件质量属性,而特性是指系统非功能(也叫非行为)部分的需求. 性能:性能就是一个东西有多快,通常指响应时间或延迟 ...

  3. 计算机终端安装成功的包 pycharm不能更新

    最近在学习python的时候遇到一个麻烦事 要用到pymssql包  在CMD下已经安装成功  但是在pycharm中运行的时候出现  没有这个包 以往的方法是在设置界面  通过+号安装需要的包  但 ...

  4. 第三个Sprint冲刺第七天(燃尽图)

  5. GCP试用到期再申请

    目标 GCP的免费试用到期了.网传可以续用,看了教程,记录下来. 法一 应该可以直接用一个新gmail账号的.这个方法的难点可能在于注册新账号有门槛.我有一个很久以前注册过的,试着找回了密码,登入GC ...

  6. Maven:The parent project must have a packaging type of POM

    在Maven Project 执行 New Maven Modual时,提示错误:The parent project must have a packaging type of POM http:/ ...

  7. Activiti解析.bpmn文件获得User Task节点的CandidateUsers特性的值

    参考文档: http://www.cnblogs.com/mingforyou/p/5351332.html http://blog.csdn.net/jackyrongvip/article/det ...

  8. Activiti中子流程:SubProcess,CallActiviti的区别

    子流程:SubProcess,CallActiviti的区别 https://community.alfresco.com/thread/221771-call-activiti-vs-subproc ...

  9. Hadoop and net core a match made in docker

    https://blog.sixeyed.com/hadoop-and-net-core-a-match-made-in-docker/

  10. [转帖]一文看懂web服务器、应用服务器、web容器、反向代理服务器区别与联系

    一文看懂web服务器.应用服务器.web容器.反向代理服务器区别与联系 https://www.cnblogs.com/vipyoumay/p/7455431.html 我们知道,不同肤色的人外貌差别 ...