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 分)的更多相关文章

  1. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  2. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

  3. PAT 1070. Mooncake (25)

    Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival.  Many types ...

  4. 1070. Mooncake (25)

    题目如下: Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many ...

  5. PAT Advanced 1070 Mooncake (25) [贪⼼算法]

    题目 Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many typ ...

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

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

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

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

  8. A1070 Mooncake (25 分)

    一.参考代码 #include<cstdio> #include<algorithm> #include<iostream> using namespace std ...

  9. PAT 1070 Mooncake[一般]

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

随机推荐

  1. rim

    “也许我们需要一些药物了”卡拉米走回他的研究室 不去看他最好的朋友的尸体. 过了今晚,他的血肉会被工虫分解. 播种机会犁过他的骨殖,种下土豆与甜菜. 索斯蹲下,不禁思考 生与死在这里太过平常 这是他们 ...

  2. Spring AOP体系学习总结

    要理解AOP整体的逻辑需要理解一下Advice,Pointcut,Advisor的概念以及他们的关系.  Advice是为Spring Bean提供增强逻辑的接口,提供了多种方法增强的方式,比如前置, ...

  3. Oracle text组件安装

    1.目标:在数据库中,安装Oracle Text组件: 970473.1 MOS文档ID     2.组件相关视图:查询验证 #查询DB中的组件: #视图:USER_REGISTRY (注册) COM ...

  4. RESTful API 学习

    /********************************************************************************* * RESTful API 学习 ...

  5. Java项目体验

    1.       JAVA开发环境安装和配置 a)         下载JDK(Java  Development  Kit) b)         安装JDK. JRE(Java  Runtime  ...

  6. 20155229 2016-2017-2 《Java程序设计》第六周学习总结

    20155229 2016-2017-2 <Java程序设计>第六周学习总结 教材学习内容总结 第十章 Java中,输入串流代表对象为java.io.InputStream,输出串流代表对 ...

  7. Executors Future Callable 使用场景实例

    https://www.jb51.net/article/132606.htm: 我们都知道实现多线程有2种方式,一种是继承Thread,一种是实现Runnable,但这2种方式都有一个缺陷,在任务完 ...

  8. 【WebForm】知识笔记

    一.ashx介绍以及ashx文件与aspx文件之间的区别 ashx是什么文件? .ashx 文件用于写web handler的. .ashx文件与.aspx文件类似,可以通过它来调用HttpHandl ...

  9. python 二维list取列

    b = [i[0] for i in a] # 从a中的每一行取第一个元素.

  10. 【模式识别】MPL,MIL和MCL

    Multi-Instance Learning (MIL) 和Multi-Pose Learning (MPL)是CV的大牛Boris Babenko at UC San Diego提出来的.其思想能 ...