PAT A1070 月饼题

PAT甲级 1070 Mooncake 贪心 【代码】PAT 1070 Mooncake 贪心。 阅读详情

PAT A1070 月饼题

这道题个人觉得不严谨……
如果所有月饼的库存量都满足不了需求量该怎么输出没有提……(如果我眼花了请指正)
测试点3我的出现了段错误,找半天发现是while循环中i的限制,原本是这样写的:


```cpp
while (true)
	{
		gram = gram + cookie[i].kucun;
		money = money + cookie[i].all;
		if (gram >= d) {
			money = money - (gram - d) * cookie[i].price;
			break;
		}
		i++;
	}
后来改成:

```cpp
while (true)
	{
		gram = gram + cookie[i].kucun;
		money = money + cookie[i].all;
		if (gram >= d) {
			money = money - (gram - d) * cookie[i].price;
			break;
		}
		i++;
        if(i == n) break;////////加了这句
	}

限制了i以后测试点3的段错误就过了……
下面是完整的代码:

#include<iostream>
#include <string>
#include <cstdio>
#include<cmath>
#include<algorithm>//min()、sort()
#include<iomanip>
#include<map>
using namespace std;
struct moon {
	double kucun;
	double all;
	double price;
};
moon cookie[1010];
bool cmp(moon a, moon b) {
	return a.price > b.price;
 }

int main() {
	int n;
	double d;
	cin >> n;
	cin >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> cookie[i].kucun;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> cookie[i].all;
		cookie[i].price = cookie[i].all / cookie[i].kucun;
	}

	sort(cookie, cookie + n, cmp);
	double gram = 0;
	double money = 0;
	int i = 0;
	while (true)
	{
		gram = gram + cookie[i].kucun;
		money = money + cookie[i].all;
		if (gram >= d) {
			money = money - (gram - d) * cookie[i].price;
			break;
		}
		i++;
        if(i == n) break;
	}

	cout << fixed<<setprecision(2) <<  money;

	
} 
【Clickhouse】Clickhouse写入报错keeper server rejected the connection during the handshake 我的clickhouse集群时不时的报这个错误All connection tries failed while connecting to ZooKeeper. nodes: xxx 到时写入数据失败 用的ck自带的keeper。你需要仔细检查ZooKeeper集群的配置和状态,确保所有节点都正常运行,并且能够正确地选举领导者。检查ZooKeeper的ACL以及ClickHouse连接所使用的凭据,确保它们被正确配置和授权。版本不兼容:有时,不同版本的软件之间可能存在不兼容性,导致连接问题。 阅读详情

相关推荐

基于 LSTM 的船舶轨迹预测,单步预测

基于 LSTM 的船舶轨迹预测,单步预测

fyuhao的博客 1万+

PAT甲级 A1070

PAT甲级 A1070 题目详情 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

weixin_44065549的博客 202

Streamlit(九) widgets-input

st.text_input / st.number_input / st.date_input / st.time_input 源码路径:${python}\Lib\site-packages\streamlit\elements\text_widgets.py(number_input.py, time_widgets.py) st.text_input st.text_input(label, value="", max_chars=None, key=None,\

heianduck的博客 3354

PAT-A1070(C/C++代码解析)

1070 Mooncake (25 分) 注:贪心算法 #include <stdio.h> //#include <string. #include <algorithm> using namespace std; struct mooncake{ double ton; double yuan; double per; }; bool cmp(mooncake,mooncake); int main () { int n,i; double ans,sum;

taylorswift的博客 381

ROS专栏—基于STM32F103的INA219电源数据采集

文章主要记录了stm32f103对ina219的数据采集

热爱生活、奋斗前行 2351

基于YOLOv8的野生菌菇检测、识别与分类系统

YOLOv8是YOLO系列模型的最新版本,继承了YOLO系列高效、精确的特点。YOLOv8采用了新的网络架构,并优化了推理速度和检测精度。与传统的目标检测算法(如Faster R-CNN)不同,YOLO模型通过一次前向传播同时完成目标定位与分类,因而具有非常高的计算效率。

YOLO 1283

PAT a1070题解

#include #include using namespace std; struct Product{ double count; double totalSell; double danjia; }product[1010]; bool cmp(Product a, Product b){ return a.danjia > b.danjia; } int main(){

Tang's学习笔记 379

树莓派 RP2350B 开发环境搭建

本文介绍了树莓派RP2350B开发环境的搭建过程。

张一西的博客 286

pat a 1070

这道题一开始我计算总profit的时候是用一个while循环的,但是这样倒数第二个测试点会有段错误。我思考了 一下认为应该是提供的月饼全卖出去都无法满足那个amount,这样的话我的while循环就会一直进行下去,直到超过了list[1010],就产生了段错误,因此要想用while循环,还需要加一些限定条件。 #include <stdio.h> #include <algori...

blxl313的博客 203

一篇文章带你快速入门 MATLAB

文章目录一、认识 MATLAB 界面二、MATLAB 的运行方式三、Matlab 中的窗口1. 命令窗口2. MATLAB的程序编辑窗口3. 工作空间窗口4. 命令历史窗口5. 图形窗口6. 当前目录窗口四、MATLAB的帮助系统1. 帮助命令2. 联机帮助五、其他知识补充1. MATLAB的搜索路径2. 变量命名规则3. M文件命名规则 一、认识 MATLAB 界面 在 MATLAB Desktop 中,工具条取代了菜单和工具栏。应用程序库收纳了 MATLAB 产品系列的应用程序,单一文件应用程序打包为一

南淮北安的博客 5125

100天精通Python(爬虫篇)——第122天:基于selenium接管已启动的浏览器(反反爬策略)

100天精通Python(爬虫篇)——第122天:基于selenium接管已启动的浏览器(反反爬策略)

努力让自己发光,对的人才能迎着光而来 13万+

PAT:A1070 Mooncake (25 分)

PAT: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...

Ecloss 376

【OpenCV C++】基本绘图操作

OpenCV C++基本绘图操作程序说明代码运行效果 程序说明 // 程序描述:OpenCV C++基本绘图操作 //参 考:毛星云《OpenCV3编程入门》 // 操作系统: Windows 10 64bit // 开发语言: C++ // IDE 版 本:Visual Studio 2019 // OpenCV版本:4.20 代码 main函数写法很简单,先创建空表Mat图像,然后点用函数绘制化学原子图,接着绘制组合图,最后显示图像。 //-------------------------

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 765

【一只蒟蒻的刷题历程】 【PAT】 A1070 月饼 (贪心)

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 ...

黑桃 322

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【PAT甲级 - C++题解】1070 Mooncake

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 820

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

PAT_A1070#Mooncake

Source: PAT A1070Mooncake(25分) Description: Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in ...

weixin_30952103的博客 131

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

PAT甲级1070(月饼)

1070 Mooncake (25 point(s)) 题目原文   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 acco...

云胡的博客 228

PAT-BASIC1020——月饼/PAT-ADVANCED1070——Mooncake

我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC 我的PAT-ADVANCED代码仓:https://github.com/617076674/PAT-ADVANCED 原题链接: PAT-BASIC1020:https://pintia.cn/problem-sets/994805260223102976/problems/9948...

清风阁 362

PAT A1070 Mooncake

分数 25作者 CHEN, Yue单位 浙江大学。

qq_51825761的博客 1527

PAT B1020 月饼 (25 分)/A 1070 Mooncake (25 分)

PAT B1020 月饼 (25 分) 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。 注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有 3 种月饼,其库存量分别为 18、15、10 万吨,总售价分别为 75、72、45 亿元。如果市场的最大需求量只有 20 万吨,那么我们最大收益策略应该是卖出全部 15 万吨第 2 种月饼、以及 5 万吨第 3 种月饼,获得 72 + 4

weixin_48165493的博客 168

PAT-A1070/B1020 Mooncake/月饼 题目内容及题解

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 ...

BourbonWhiskey 的博客 651

PAT-A 1070 Mooncake (25 分) / PAT-B 1020 月饼(25分)

题目中给出的价格是总价格,月饼的库存量也可能是浮点数(题目只说是正数)。 将所有的月饼按照单价从高到低排序,然后逐个遍历月饼,比较月饼库存和市场需求,对总利润和市场需求进行更新即可。

qq_38127801的博客 210

A1070/B1020 PAT甲级JAVA题解 Mooncake

测试点3非零返回,把库存类型改成Double可以解决。给出月饼种类,需求库存,每种月饼的库存和总价。使用Scanner读取数据会超时。根据单价比较后计算出最大利益。

qq_49695680的博客 776

PAT-A1070 Mooncake 贪心

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

gdc6916的博客 3万+

PAT A1070

题目: 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....

xiao1guaishou的博客 110

【PAT甲级】1070 Mooncake (25 分)【贪心】

【PAT甲级】1070 Mooncake (25 分)【贪心】 思路 题目给出每种月饼的总重量和总价值,由此可以得到月饼的单价,这些信息用结构体存储 对数组按照单价从高到低进行排序 月饼总需求量sum是固定的,因此优先采购单价高的(遍历操作即可) 代码 #include <iostream> #include <algorithm> #include <cstring> using namespace std; struct mooncake { do

郭同学如是说 171
上一篇: PAT A1084 用STL中的map实现
下一篇: 解决Pyinstaller打包Qt designer的两个问题
mAN_DOm
博客等级 码龄8年 13粉丝 16原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值