PAT_A1070#Mooncake
Source:
Description:
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 (≤), the number of different kinds of mooncakes, and D (≤ 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
Keys:
- 贪心
- ven要用double存储,int存储精度会有误差
Code:
/*
Data: 2019-07-22 19:35:47
Problem: PAT_A1070#Mooncake
AC: 13:45 题目大意:
给出各种月饼的库存和价格,和市场需求总量,求最大利润
输入:
第一行给出,月饼种类N<=1e3,市场需求总量D<=500
第二行给出,库存量
第三行给出,价格
输出:
最大利润(两位小数) 基本思路:
根据贪心算法,总是优先选择单价最高月饼
*/
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e3+;
struct node
{
double ven,prs;
}mcake[M]; bool cmp(const node &a, const node &b)
{
return a.prs/a.ven > b.prs/b.ven;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,d;
scanf("%d%d", &n,&d);
for(int i=; i<n; i++)
scanf("%lf", &mcake[i].ven);
for(int i=; i<n; i++)
scanf("%lf", &mcake[i].prs);
sort(mcake,mcake+n,cmp);
double ans=;
for(int i=; i<n; i++)
{
if(d > mcake[i].ven)
{
ans += mcake[i].prs;
d -= mcake[i].ven;
}
else if(d <= mcake[i].ven)
{
ans += d*(mcake[i].prs/mcake[i].ven);
break;
}
}
printf("%.2f\n", ans); return ;
}
PAT_A1070#Mooncake的更多相关文章
- 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个月饼 接 ...
- 1070. Mooncake (25)
题目如下: Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many ...
- PAT1070:Mooncake
1070. Mooncake (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mooncake is ...
- A1070. Mooncake
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- HDU 4122 Alice's mooncake shop (RMQ)
Alice's mooncake shop Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- PAT 1070 Mooncake[一般]
1070 Mooncake (25)(25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Aut ...
随机推荐
- winform中的小技巧【自用】
一.C#在WinForm中怎样让多行TEXTBOX的换行 今天做项目,有一段提示文字需要弹出来,由于太长,我就想能不能让它换行.然后就百度了一下,嘿嘿,方法很好用哦. 原文链接:https://blo ...
- MySQL高级学习笔记(五):查询截取分析
文章目录 慢查询日志 是什么 怎么玩 说明 查看是否开启及如何开启 默认 开启 那么开启了慢查询日志后,什么样的SQL才会记录到慢查询日志里面呢? Case 配置版 日志分析工具mysqldumpsl ...
- grep 后加单引号、双引号和不加引号的区别
请尊重版权,原文地址:https://blog.csdn.net/cupidove/article/details/8783968 单引号: 可以说是所见即所得:即将单引号内的内容原样输出,或者描述为 ...
- The request with exception: The SSL connection could not be established, see inner exception. requestId 解决方案
DOTNET CORE 部署 Centos7 抛出异常 环境变量如下: .NET Core SDK (reflecting any global.json): Version: 2.2.401 Com ...
- linux 服务器内存占用统计
当前内存占用率的计算,是根据top命令显示的Mem.used除以Mem.total得到. Mem.total:表示总物理内存. Mem.used: 表示内核控制的内存数,除了应用程序使用的内存外,还包 ...
- FrameWork内核解析之WindowManagerService(一)中篇
阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680 1.WMS概述 WMS是系统的其他服务,无论对于应用开发还是Framew ...
- koa2实现登录注册功能(ejs+mongodb版)
gtihub仓库地址:(由于国内处于敏感时期,github暂时无法访问) 主要使用的中间件: "ejs": "^2.7.1",(渲染模板) "koa& ...
- postgresql like 中的转义
select * from tb_org where char_length(xdm)>8 and xdm not like '%*_%' ESCAPE '*' ESCAPE 后面的 * 是转 ...
- nodejs 模板引擎ejs的简单使用
ejs1.js /** * Created by ZXW on 2017/11/9. */ var ejs=require('ejs'); ejs.renderFile("},functio ...
- 2.java中c#中statc 静态调用不同之处、c#的静态构造函数和java中的构造代码块、静态代码块
1.java和c#静态成员调用的不同之处 static 表示静态的,也就是共享资源,它是在类加载的时候就创建了 java中 可以通过实例来调用,也可以通过类名.成员名来调用,但是一般最好使用类名. ...