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 ...
随机推荐
- 如何在原生Android项目里嵌入Cordova
背景: 这段时间在维护一个Cordova混合项目,以前稍微接触过Cordova,也写过简单的纯纯的Cordova的Demo,但是没有尝试过混合原生的Cordova. 在接到项目后比较了一下项目架构和C ...
- PHP的安装配置
一.安装 PHP的安装可以很简单的使用yum命令进行安装. #添加php7.0源(这是centos7的命令,centos6.5的命令不同,不要照搬)rpm -Uvh https://dl.fedora ...
- HDU1251-统计难题-map+输入
Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input输入数据的第一部分 ...
- upc组队赛5 Ingenious Lottery Tickets【排序】
Ingenious Lottery Tickets 题目描述 Your friend Superstitious Stanley is always getting himself into trou ...
- jupyter notebook的魔法命令 % %%
Magic单元分为两种,一种是line magics,另外一种cell magics. Line magic是通过在前面加%,表示magic只在本行有效. Cell magic是通过在前面加%%,表示 ...
- vue/cli3引入cesium
vue/cli3引入cesium 一开始用了webpack结合vue引入vue:结果是各种bug,搞了半天.最后问了基友,发现vue脚手架这个·简单高效的方法,只需要几行代码就轻松地搞定啦! 方案一. ...
- Django 自定义模型管理器(Manager)及方法
转载自:https://www.cnblogs.com/sui776265233/p/11571418.html 1.自定义管理器(Manager) 在语句Book.objects.all()中,ob ...
- Cocos2d-x之Director
| 版权声明:本文为博主原创文章,未经博主允许不得转载. Director类简介 在Cocos2d-x-3.x引擎中,采用节点树形结构来管理游戏对象,一个游戏可以划分为不同的场景,一个场景又可以分 ...
- Sqlplus常用指令
一.ORACLE的启动和关闭1.在单机环境下2.在双机环境下二.Oracle数据库有哪几种启动方式1.startup nomount 非安装启动,这种方式启动下可执行:重建控制文件.重建数据库2.st ...
- 牛客小白月赛18 G Forsaken的三维数点
思路: 这是一道树状数组和二分的题,用线段树空间直接爆,时间也会超 然后这道题我犯了一个很低级的错误,导致我wa了十发左右,一个int型变量用lld输入,然后他给的提示是运行错误,我哭了,我一直以为是 ...