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 ...
随机推荐
- L228 the complicated issue of equality: non-disabled actors play disabled roles
Bryan Cranston’s defence of playing a wheelchair user in the new comedy-drama The Upside has underli ...
- php 值引用
1.值传递 复制代码 代码如下: <?php function exam($var1){ $var1++: echo "In Exam:" . $var1 . "& ...
- mdadm 创建md 删除md步骤
最近在使用mdadm创建和删除RAID设备.但是在创建和删除过程中会出现创建md0重启后变成md127,删除md127重启后又重新出现的状况.在网上搜索了一下,总结如下: 创建: 1. mdad ...
- Texas Instruments matrix-gui-2.0 hacking -- helper_functions.php
<?php # PHP_SELF: 但前正在执行脚本的文件名,与document root相关 # QUERY_STRING: 查询(query)的字符串 $cachefile = " ...
- shell 脚本实战笔记(7)--集群网络相关知识和环境搭建
前言: 对网络相关的知识, 做下笔记. 包括IP地址A/B/C的分类, 静态地址的配置/DNS配置, 以及网卡相关信息查看. *) A/B/C/D类网络地址的划分 IP地址=网络地址+主机地址 或 I ...
- linux-锁屏时间设置
系统:ubuntu16.04 操作步骤 设置setting -> System Settings -> Brightness&lock, 在界面中选择想要的设置即可: 参考 1.百 ...
- convert CAN frame
前言 最近了解了一些socket can的知识点,本文主要介绍如何将数据转换为CAN报文,前提是已经确定CAN的传输协议. 本文使用的CAN报文共有22条,这些报文共用一个can id,每条报文使用序 ...
- ubuntu mongodb backup/restore (备份和恢复)
备份(导出) 1.导出单个collection-.json格式 mongoexport --host:127.0.0.1 --port:27017 --db test --collection tes ...
- BZOJ4310: 跳蚤 【后缀数组+二分】
Description 很久很久以前,森林里住着一群跳蚤.一天,跳蚤国王得到了一个神秘的字符串,它想进行研究.首先,他会把串 分成不超过 k 个子串,然后对于每个子串 S,他会从S的所有子串中选择字典 ...
- 51Nod:1265 四点共面
计算几何 修改隐藏话题 1265 四点共面 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出三维空间上的四个点(点与点的位置均不相同),判断这4个点 ...