[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;
}

相关内容

热门资讯

【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
牛客计算器的改良(Python... 文章目录1.题目描述2.输入描述:3.输出描述:4.示例15.分析6.代码7.结语 链接࿱...
【前端】‘??‘与‘||‘有什... 0 问题 经常写const data = res.data.a ?? ''或者const d...
文本生成视频Make-A-Vi... Meta公司(原Facebook)在今年9月29日首次推出一款人工智能系...
【Redis】Redis持久化... 目录 1.Redis持久化 1.1.RDB持久化 1.1.1.执行时机 1.1.2.RDB原理 1....