[PAT-Advanced] B1020/A1070. Mooncake (25)

news/2024/4/19 10:07:55/文章来源:https://blog.csdn.net/ztmajor/article/details/128110935

文章目录

  • 总题解目录
  • 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 <stdio.h>
#include <stdlib.h>
#include <algorithm>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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_39091.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Linux】高频指令及简单的vim使用(0基础带你快速入门)

目录 一、目录操作指令 1.1、ls 1.2、pwd 1.3、cd 1.4、touch 1.5、cat 1.6、echo 1.7、mkdir 1.8、rm 1.9、mv 1.10、cp 二、Linux中如何手动安装插件 三、vim 3.1、打开文件 3.2、编辑文件 3.3、保存退出 一、目录操作指令 1.1、ls 语法&#xff1a; 第一种&#…

Android中简单使用aspectj

Android中简单使用aspectj 前言&#xff1a; 面向切面编程&#xff08;AOP是Aspect Oriented Program的首字母缩写&#xff09;,这种在运行时&#xff0c;动态地将代码切入到类的指定方法、指定位置上的编程思想就是面向切面的编程. 1.简介&#xff1a; 在Android中使用注解…

onnx删除无用属性

这里写自定义目录标题在推理onnx模型时&#xff0c;报了一个错&#xff0c;如下&#xff1a;InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : This is an invalid model. In Node, ("Conv_0", Conv, "", -1) : ("x": tensor(float),&q…

xxljob

分为调度中心 执行器 调度中心&#xff1a;提供可视化界面&#xff0c;配置定时任务&#xff0c;定时去调用执行器 调度中心执行器管理&#xff1a;每个springboot作为执行器&#xff0c; 也就是执行器的标识 任务管理&#xff1a;选中执行器&#xff0c;创建改该执行器下的任…

c++ - 第15节 - 二叉树进阶

1. 二叉搜索树 1.1.二叉搜索树概念 二叉搜索树又称二叉排序树&#xff0c;它或者是一棵空树&#xff0c;或者是具有以下性质的二叉树: 若它的左子树不为空&#xff0c;则左子树上所有节点的值都小于根节点的值若它的右子树不为空&#xff0c;则右子树上所有节点的值都大于根节…

iphone怎么传数据到另一个手机,苹果如何转移数据到新手机,两台iphone怎么同步所有数据

换新手机后&#xff0c;需要迁移旧苹果手机的数据到新苹果手机里面&#xff0c;那么&#xff0c;iphone怎么传数据到另一个手机&#xff1f;本篇文章带您深度了解苹果手机的数据传输技巧。 方法一、通过“快速开始”传输数据 苹果手机如何数据传输&#xff1f;我记得之前换 iP…

沉睡者IT - Web3的未来在哪里?

欢迎关注沉睡者IT&#xff0c;点上面关注我 ↑ ↑ 专家说&#xff0c;web3将颠覆现在的互联网 今天我们来讨论一下&#xff0c;web3会颠覆现在的互联网呢&#xff1f; 看了小编往期的作品你应该知道&#xff0c;如果同样的作品发在web3平台上&#xff0c;你将获取到收益。 那…

Codeforces Round #290 (Div. 2) C. Fox And Names

翻译&#xff1a; Fox Ciel将发表一篇关于FOCS (Fox操作的计算机系统&#xff0c;发音:“Fox”)的论文。她听到一个谣言:报纸上的作者名单总是按照词典顺序排列的。 在查看了一些例子后&#xff0c;她发现有时这不是真的。在一些论文中&#xff0c;作者的名字没有按照正常意义…

干货 | 提前在开发阶段暴露代码问题,携程Alchemy代码质量平台

作者简介Lyan&#xff0c;携程资深后端开发工程师&#xff0c;负责自动化测试框架及平台类工具开发&#xff0c;关注Devops、研发效能领域。一、背景随着敏捷开发&#xff0c;DevOps开发模式的流行&#xff0c;代码质量分析作为研发质量保证体系的重要组成部分&#xff0c;不仅…

DCDC--Burst Mode和Pulse Skipping Mode

1、Burst Mode和Pulse Skipping Mode&#xff08;PSM&#xff09;的区别 Burst Mode ≠ Pulse Skipping Mode&#xff0c;论坛有人认为Burst Mode就是Pulse Skipping Mode&#xff0c;这是不对的。 以LTC3624为例&#xff1a; Burst Mode operation provides the highest ef…

(一)DepthAI-python相关接口:OAK Device

消息快播&#xff1a;OpenCV众筹了一款ROS2机器人rae&#xff0c;开源、功能强、上手简单。来瞅瞅~ 编辑&#xff1a;OAK中国 首发&#xff1a;oakchina.cn 喜欢的话&#xff0c;请多多&#x1f44d;⭐️✍ 内容可能会不定期更新&#xff0c;官网内容都是最新的&#xff0c;请查…

数据结构初阶--栈和队列(讲解+类模板实现)

栈的概念和结构 栈&#xff1a;一种特殊的线性表&#xff0c;其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端称为栈顶&#xff0c;另一端称为栈底。栈中的数据元素遵守后进先出LIFO&#xff08;Last In First Out&#xff09;加粗样式的原则。 入…

Redis数据结构和类型

Redis 包含五种数据类型&#xff0c;分别为String、List、Hash、Set、ZSet 底层实现的数据结构包SDS、双向链表、压缩列表、哈希表、整数集合、跳表 redis结构图数据类型和数据结构的关系Redis六种数据结构 一、动态字符串(SDS) Redis 是用 C 语言实现的&#xff0c;但是它…

在Word、WPS中插入AxMath公式导致行间距异常的解决办法

引言 我最近需要写一些文章&#xff0c;在排版时发现AxMath插入的公式竟然会导致行间距异常&#xff0c;如下图所示&#xff1a; 查遍互联网&#xff0c;最有效的办法竟然要取消文档网格对齐&#xff0c;这对于一些严格要求的场合是非常不利的&#xff0c;经过我的尝试&#…

SpringBoot3.0正式发布,我来尝尝鲜

GraalVM 版本&#xff1a;graalvm-ce-java17-22.3.0 SpringBoot3.0 中最重要的特性就是对 GraalVM 的支持&#xff0c;从而达到更快的启动速度&#xff0c;有两种使用方式。 利用 GraalVM 构建可执行文件 因为需要利用 GraalVM 来打包可执行文件&#xff0c;所以需要你的机器上…

Casein-PEG-Indocyanine green 络蛋白-聚乙二醇-吲哚菁绿 Casein-ICG

产品名称&#xff1a;络蛋白-聚乙二醇-吲哚菁绿 英文名称&#xff1a;Casein-PEG-Indocyanine green 质量控制&#xff1a;95% 原料分散系数PDI&#xff1a;≤1.05 存储条件&#xff1a;-20C&#xff0c;避光&#xff0c;避湿 用 途&#xff1a;仅供科研实验使用&#xff0c;…

Ansible 企业级自动化运维实战

一、Ansible 简介 如果Ansible不采用0mq(ZeroMQ),在操作1000个以下的节点性能还可以,如果操作1000个以上的节点,性能就很差。 目前来说Ansible支持local,ssh,0mq,Ansible用ssh来管理被管理主机是最常见的方法。 saltstack简称salt,默认采用0mq(ZeroMQ),支持数万…

TaWRKY19/61/82激活糖转运蛋白TaSTP3从而增强小麦条锈病敏感性

文章信息 题目&#xff1a;Sugar transporter TaSTP3 activation by TaWRKY19/61/82 enhances stripe rust susceptibility in wheat 刊名&#xff1a;New Phytologist 作者&#xff1a;Baoyu Huai&#xff0c;Zhensheng Kang,Jie Liu et al. 单位&#xff1a;Northwest A&…

麒麟信安携手河南IT联盟召开 《麒麟信安信创应用解决方案》线上分享会

在党政及金融、交通、能源等重要行业的信创应用步伐逐步加快的背景下&#xff0c;各行业均面临着不同程度的国产化落地难题。11月29日下午&#xff0c;麒麟信安与河南省信息协会IT产业分会&#xff08;河南IT联盟&#xff09;携手召开《麒麟信安信创应用解决方案》线上分享会&a…

ARM汇编之乘法指令

ARM汇编之乘法指令前言 首先&#xff0c;请问大家几个小小问题&#xff0c;你清楚&#xff1a; 乘法指令有哪些种类呢&#xff1f;ARM乘法指令具体的使用场景又有哪些&#xff1f; 今天&#xff0c;我们来一起探索并回答这些问题。为了便于大家理解&#xff0c;以下是本文的…