1070. Mooncake (25)

时间限制
100 ms

内存限制
65536 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

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<iostream>
#include<cstdio>
#include<stdio.h>
#include<algorithm>using namespace std;struct cake
{double num;double sum;double price;}c[10010];int cmp(cake c1, cake c2)
{return c1.price > c2.price;
}int main()
{int n, demand;double money = 0;int m = 0;cin >> n >> demand;for (int i = 0; i < n; i++)cin >> c[i].num;for (int i = 0; i < n; i++){cin >> c[i].sum;c[i].price = c[i].sum / c[i].num;}sort(c, c + n, cmp);int i = 0;while (m+c[i].num <= demand&&i<n){money += c[i].sum;m += c[i].num;i++;}if (i<n)money = (demand - m)*c[i].price + money;/*for (int i = 0; i < n; i++){if (m + c[i].num <= demand){money += c[i].sum;m += c[i].num;}else{money = (demand - m)*c[i].price + money;break;}}*/printf("%.2lf", money);system("pause");return 0;
}

PAT-A-1070. Mooncake (25)相关推荐

  1. PAT甲级1070 Mooncake:[C++题解]贪心

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 对单件从高到低排序. 需要注意的是总需要量d设成double,不要设成int. ac代码 #include<bits/stdc ...

  2. PAT (Advanced Level) 1070. Mooncake (25)

    简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...

  3. PAT甲题题解-1070. Mooncake (25)-排序,大水题

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  4. 1070 Mooncake (25 分)【难度: 简单 / 知识点: 贪心】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805399578853376 没啥说的,PAT乙级的原题好像是. #inc ...

  5. 【测试点2分析】:1020 月饼 (25分)(甲级 1070 Mooncake (25 分))

    立志用更少的代码做更高效的表达 PAT甲级最优题解-->传送门 Pat乙级最优化代码+题解+分析汇总-->传送门 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼.现 ...

  6. pat1070. Mooncake (25)

    1070. Mooncake (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mooncake is ...

  7. PAT A1070:Mooncake之贪心求解

    题目描述 1070 Mooncake (25分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Aut ...

  8. PAT 1069 1070 1071 1072

    pat 1069 The Black Hole of Numbers 水题,代码如下: 1 #include<cstdio> 2 #include<cstdlib> 3 #in ...

  9. PAT 1085 PAT单位排行(25)(映射、集合训练)

    1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤10​5​​),即考生人数.随 ...

最新文章

  1. Be a person
  2. java word openoffice_java 使用openoffice 转换文档,成.pdf,实现在线预览效果
  3. boost::detail模块实现数字特征的测试程序
  4. LIS路径记录(UVA481)
  5. js unix时间戳转换
  6. PaperNotes(7)-GANs模式坍塌/训练不稳定
  7. nlp5-n-gram/语言模型(数据平滑方法
  8. zabbix-3.0.4安装部署
  9. @程序员,物联网软件开发不得不克服的七大挑战
  10. iOS----------APP怎样做更安全
  11. 自学人工智能途径_成为数据科学家,AI或ML工程师的自学途径
  12. CF914D Bash and a Tough Math Puzzle
  13. r语言和python培训_Python 和R语言
  14. idm由于法律原因无法下载怎么办?
  15. 输入关键字生成对联_自动对联工具
  16. Python中的Bunch模式
  17. c语言如何判断一个带分数整数部分,2013年第四届蓝桥杯省赛C语言B组
  18. VIPS 98经济型漏电继电器
  19. windows网络服务进程管理dos命令
  20. scrapy 豆瓣短评 数据分析 + 中文情感分析 + 可视化 (一)

热门文章

  1. 用java生成高并发下的唯一的案件编号:
  2. 中山大学计算机系女教授,谢晓华(中山大学数据科学与计算机学院副教授)_百度百科...
  3. 【从0到1实现多人FPS房间对战游戏】
  4. 可用Active Desktop Calendar V7.86 注册码序列号
  5. 贵州大学计算机类是211吗,贵州大学的211有用吗?贵大的211在外省好找工作吗?...
  6. 应用启动 应用启动优化
  7. c语言--洛谷p1308统计单词数
  8. biostar handbook|如何模拟NGS测序结果
  9. html 横线的代码
  10. 编程学习笔记之python深入之装饰器案例及说明文档[图]