[PAT-Advanced] B1020/A1070. Mooncake (25)
创始人
2024-03-02 15:10:02
0

文章目录

  • 总题解目录
  • B1020/A1070. Mooncake (25)
  • Input Specification:
  • Output Specification:
  • Sample Input:
  • Sample Output:
  • Analysis
  • C++ Code

总题解目录

[PAT- Advanced Level] 甲级题解目录(Advanced Level)

B1020/A1070. 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 regions 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

Analysis

  • 已知月饼种类N,表示月饼的市场最大需求量D,以及每种月饼的数量和总价。

  • 求根据市场最大需求量,这些月饼的最大销售利润为多少。

C++ Code

//NKW 乙级真题1010
#include 
#include 
#include using namespace std;
const int maxn = 1010;typedef struct mooncake{double value;double weight;double vmw;
}mooncake;bool cmp(mooncake a, mooncake b){return a.vmw > b.vmw;
}double getvalue(mooncake a[], int n, double need){int i;double sum = 0;for (i = 0; i < n; i++)	{if (a[i].weight <= need){sum += a[i].value;need -= a[i].weight;}else{sum += a[i].vmw * need;break;}}return sum;
}int main(){int  n;double d;mooncake cake[maxn];int i;scanf("%d %lf", &n, &d);for (i = 0; i < n; i++)scanf("%lf", &cake[i].weight);for (i = 0; i < n; i++){scanf("%lf", &cake[i].value);cake[i].vmw = cake[i].value / cake[i].weight;}sort(cake, cake + n, cmp);printf("%.2f\n", getvalue(cake, n, d));return 0;
}

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
有效的括号 一、题目 给定一个只包括 '(',')','{','}'...
【Ctfer训练计划】——(三... 作者名:Demo不是emo  主页面链接:主页传送门 创作初心ÿ...