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个月饼 接 ...
随机推荐
- Mvc_前后端绑定数据json集合
ViewBag.SysModuleList =new List<SysModule>(){.....}; var data = @Html.Raw(Json.Encode(ViewBag ...
- Linux下"负载均衡+高可用"集群的考虑点 以及 高可用方案说明(Keepalive/Heartbeat)
当下Linux运维技术越来越受到企业的关注和追捧, 在某些企业, 尤其是牵涉到电子商务和电子广告类的网站,通常会要求作负载均衡和高可用的Linux集群方案.那么如何实施Llinux集群架构,才能既有效 ...
- Mysql抓包工具 - MySQL Sniffer 使用小结 (含带general_log日志)
在mysql运维工作中,一般会使用tcpdump做一些分析(直接读分析日志比较难以看明白,在数据库连接值高时使用):对于mysql实时的连接监控分析,通常会使用"mysqladmin/sho ...
- 团队作业M1反思
经过这两个多月以来的软件工程的学习,还有团队项目的经历,总结反思如下: 首先,一个月的软件工程团队项目的进行让我对软件开发有了比较实际的认识,以前我们的编程多是个人编程,两人编程,程序难度低,代码量少 ...
- Linux内核设计与实现 第三章
1. 进程和线程 进程和线程是程序运行时状态,是动态变化的,进程和线程的管理操作都是由内核来实现的. Linux中的进程于Windows相比是很轻量级的,而且不严格区分进程和线程,线程不过是一种特殊的 ...
- Java代码安全
https://www.owasp.org/index.php/Category:Java
- Node fs模块同步读取写入追加
JS文件中const fs = require("fs");console.log("开始进入文件读取.."); //同步的写入var data = fs.re ...
- 关于适用base64对图片进行编码在服务器上性能的相关讨论
周五在写open api的时候 和
- js簡介
js是腳本語言: js適用於服務器.pc.平板電腦.智能手機: js是最流行的編程語言,使用與html和前段: js是一種輕量級編程語言: js能被所有的現代瀏覽器執行: js和java是完全不同的編 ...
- Jenkins之Linux和window配置区别
一.命令行配置 windows: java -jar .\libs\gen-html-report-1.0-SNAPSHOT.jar .\reports_%BUILD_NUMBER%.html .\t ...