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 ...
随机推荐
- #define学习
C语言中数据有常量和变量,其中定义常量主要有两种方法,这里主要学习#define定义常量的方法. 1.#define定义数字宏常量 例子如下: 1 2 3 4 5 6 7 8 9 10 #includ ...
- Oracle架构实现原理、含五大进程解析(图文详解)
目录 目录 前言 Oracle RDBMS架构图 内存结构 系统全局区SGA 高速缓存缓冲区数据库缓冲区 日志缓冲区 共享池 其他结构 进程结构 用户连接进程 用户进程User Process Ser ...
- 使用密码登陆Amazon EC2
用的是亚马逊推荐的系统:Amazon Linux AMI 2015.09.1 (HVM) 创建instance后,会有一个pem的key使用该密钥登陆到服务器上后,默认用户名为 ec2-user 直接 ...
- Web RTC录视频
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 点读系列《jmeter官方用户手册》
官网:http://jmeter.apache.org/usermanual/ 说明:十八元件.十九属性.二十函数,涉及清单内容暂未仔细阅读,个人觉得一是仅供使用参考,二是适合单独写文章来解读 一.让 ...
- Java继承和构造函数
构造函数不是类的成员,它们不是由子类继承的.它们用于初始化实例变量. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 class CSuper { public ...
- shell编程:命令替换的运用
命令替换,有两种方式 方式一:`command` 方式二:$(command) user.sh 查找系统中所有的用户,并且输出 #!/bin/bash nginx=`netstat -tnlp | | ...
- [已解决]报错: No module named pip
cmd中敲命令: python -m ensurepip 更新升级pip命令: python -m pip install --upgrade pip
- 学习Spring时用Idea中Maven Project创建一个子module出现了子pom.xml没有继承父pom.xml
正常情况: 解决方法: 1.首先点击父项目右键 -->new-->Module 2.不用点击create from achetype直接点击next 3.在ArtifactId输入你要mo ...
- Spring 使用@Async出现循环依赖Bean报错的解决方案
初现端倪 Caused by:org.springframework.beans.factory.BeanCurrentlyInCreationException: Errorcreating bea ...