1070 Mooncake (25 分)
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
分析:贪心水题。。
/** * Copyright(c) * All rights reserved. * Author : Mered1th * Date : 2019-02-25-21.32.50 * Description : A1070 */ #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<string> #include<unordered_set> #include<map> #include<vector> #include<set> using namespace std; ; struct Node{ double amounts; double sell; double price; }node[maxn]; bool cmp(Node a,Node b){ return a.price>b.price; } int main(){ #ifdef ONLINE_JUDGE #else freopen("1.txt", "r", stdin); #endif int n; double d; cin>>n>>d; ;i<n;i++){ cin>>node[i].amounts; } ;i<n;i++){ cin>>node[i].sell; node[i].price=node[i].sell/node[i].amounts; } sort(node,node+n,cmp); double sum=0.0; ;i<n;i++){ if(node[i].amounts<d){ sum+=node[i].sell; d-=node[i].amounts; } else{ sum+=node[i].price*d; break; } } printf("%.2f",sum); ; }
1070 Mooncake (25 分)的更多相关文章
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- PAT 1070. Mooncake (25)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- 1070. Mooncake (25)
题目如下: Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many ...
- PAT Advanced 1070 Mooncake (25) [贪⼼算法]
题目 Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many typ ...
- PAT (Advanced Level) 1070. Mooncake (25)
简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...
- PAT甲题题解-1070. Mooncake (25)-排序,大水题
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- A1070 Mooncake (25 分)
一.参考代码 #include<cstdio> #include<algorithm> #include<iostream> using namespace std ...
- PAT 1070 Mooncake[一般]
1070 Mooncake (25)(25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Aut ...
随机推荐
- linux C 内存分配(~道的光芒四射~)
总结一下C语言中基本的内存分配,加深对内存管理的印象,一步一步走山路~~~~~~~~ 1. 程序和进程 问题:程序和进程各是什么? 程序 只是一段可以执行的代码文件,通俗讲在 linux 上就是一个 ...
- OC基础:继承.初始化方法,便利构造器 分类: ios学习 OC 2015-06-16 19:27 84人阅读 评论(0) 收藏
继承: 1.单向继承,一个类只能有一个父类,一个父类可以有多个子类. 2.单向继承,基类(根类)是OSObject 3.子类可以继承父类的属性和方法 当父类的方法不满足子类的需求时,子类可以重写父类的 ...
- 算法训练 P1102
算法训练 P1102 时间限制:1.0s 内存限制:256.0MB 定义一个学生结构体类型student,包括4个字段,姓名.性别.年龄和成绩.然后在主函数中定义一个结构体数组( ...
- IISExpress 开放局域网访问
1. 设置 IISExpress 配置文件 applicationhost.config VS2015 :这个配置文件 在工程目录下的 .vs/config 隐藏目录 其他版本 :在用户目录中的 II ...
- C 枚举 相同的值
/********************************************************************************* * C 枚举 相同的值 * 说明: ...
- 【opencv基础】pointPolygonTest
pointPolygonTest opencv函数 pointPolygonTest: C++: double pointPolygonTest(InputArray contour, Point2f ...
- 【linux基础】ubuntu如何查看linux的内核版本和系统版本
参考 1.查看linux内核和系统版本: 完
- hdu 5185 dp(完全背包)
BC # 32 1004 题意:要求 n 个数和为 n ,而且后一个数等于前一个数或者等于前一个数加 1 ,问有多少种组合. 其实是一道很水的完全背包,但是没有了 dp 的分类我几乎没有往这边细想,又 ...
- Sublime Text3 使用
注: 1.绿色版的某些插件有问题,导致某些插件无法使用,而且无法删除和安装,需要删除Data/Cache目录,重新安装无法使用的插件 2.绿色版无法编译python,可使用安装版安装sublime后, ...
- listening for variable changes in javascript
https://stackoverflow.com/questions/1759987/listening-for-variable-changes-in-javascript