码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • [PAT-Advanced] B1020/A1070. Mooncake (25)


    文章目录

    • 总题解目录
    • 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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
  • 相关阅读:
    Dubbo-入门指南+实例
    Ubuntu部署K8S
    牛视源码定制,抖音矩阵系统,别和谐啊、、、
    Elasticsearch基础篇(四):Elasticsearch7.x的官方文档学习(Set up Elasticsearch)
    jasypt 配置文件加解密
    【MATLAB源码-第45期】基于matlab的16APSK调制解调仿真,使用卷积编码软判决。
    C#进阶高级语法之LINQ:深入分析LINQ的查询表达式、延迟执行与PLINQ高级特性
    用模板完成顺序栈和顺序队列
    leetcode:1323. 6 和 9 组成的最大数字(python3解法)
    select基础查询
  • 原文地址:https://blog.csdn.net/ztmajor/article/details/128110935
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号