CCF 201703-1 分蛋糕 C++ need attention

分蛋糕(c++) 每到六一儿童节,美丽的老师都会给与或非的乖同学们分蛋糕,但是蛋糕有N个,要分给M个孩子。为了公平起见,老师想让每位同学分到的蛋糕都一样多,如果不够的话从自己的K个蛋糕中拿出一些分给孩子们。你能帮助老师算出能否让每位同学分到的蛋糕数量都一样吗本题有T组数据每行给你三个整数NMK1≤T≤2001≤NMK≤100000如果能使每个孩子得到的苹果数目一样输出YES,否则输出NO。 阅读详情

在这里插入图片描述

//设置一个sum记录当前蛋糕总重,设置一个count记录得到蛋糕的人;要注意即使最后一个人得到的蛋糕不够k,也算得到了蛋糕
#include <iostream>
using namespace std;
int main()
{
	int n,k,a,count=0,sum=0;
	cin >> n >> k;
	for(int i=0;i<n;i++)
	{
		cin >> a;
		sum+=a;
		if(sum>=k)
		{
			count++;
			sum=0;
		}
	}
	if(sum>0) count++;
	cout << count << endl;
	return 0;
}
 

注意即使最后一个人得到的蛋糕不够k,也算得到了蛋糕

CCF计算机软件能力认证试题练习:201703-1 分蛋糕 分蛋糕 来源: 标签: 参考资料: 相似题目: 题目 小明今天生日,他有n块蛋糕要分给朋友们吃,这n块蛋糕(编号为1到n)的重量分别为a1, a2, …, an。小明想分给每个朋友至少重量为k的蛋糕。小明的朋友们已经排好队准备领蛋糕,对于每个朋友,小明总是先将自己手中编号最小的蛋糕分给他,当这个朋友所分得蛋糕的重量不到k时,再继续将剩下的蛋糕中编号... 阅读详情

相关推荐

csp-分蛋糕C++100分

#include<iostream> using namespace std; int main(){ int n,k,a[1000],p,q; cin>>n>>k; for(int i=0;i<n;++i){ cin>>a[i]; } q=0; for(int j=0;j<n;++j){ p=a[j]; wh...

编程知识分享,主打前端 3万+

acwing 3242. 分蛋糕 C++

acwing 3242. 分蛋糕 C++ 小明今天生日,他有 n 块蛋糕要分给朋友们吃,这 n 块蛋糕(编号为 1 到 n)的重量分别为 a1,a2,…,an。 小明想分给每个朋友至少重量为 k 的蛋糕。 小明的朋友们已经排好队准备领蛋糕,对于每个朋友,小明总是先将自己手中编号最小的蛋糕分给他,当这个朋友所分得蛋糕的重量不到 k 时,再继续将剩下的蛋糕中编号最小的给他,直到小明的蛋糕分完或者这个朋友分到的蛋糕的总重量大于等于 k。 请问当小明的蛋糕分完时,总共有多少个朋友分到了蛋糕。

m0_73896954的博客 643

切蛋糕 c++版

一个矩形蛋糕,长宽都是正整数,要求用户输入蛋糕的长和宽,并且由用户决定切分成多少块,编写一个函数求怎样切割使得最大的那一块面积最小,并输出最大的那一块的面积。

【c++】分蛋糕(数论)

分蛋糕题目难度:简单时间限制:1024ms内存限制:128mb把一块 m 厘米 * n 厘米的蛋糕分割成同样大的正方形,如果要求,分割出的正方形蛋糕最大边长是多少厘米?(最少不能少于 1 厘米* 1 厘米)如:一块 6 厘米 * 4 厘米的蛋糕,能够分割的最大的正方形的边长为 2 厘米。两个整数 m 和 n。能够分割的最大正方形的边长。6 42对于80%数据,1≤n,m≤10^7,对于100%数据,1≤n,m≤10^18,

ptyz306的博客 646

9 HAL库驱动框架简述(STM32HAL库)

HAL库外设的使用步骤总结如下:1、定义并填充xxx外设句柄结构体。2、如果遵循HAL库规范,通过HAL_xxx_MspInit()函数,实现外设底层资源的初始化,包括但不限于GPIO、时钟、DMA、中断等资源的初始化。3、调用HAL库的对应外设初始化函数,形如:HAL_xxx_Init()。4、初始化完成,开始使用外设。5、使用方法具体查看对应外设的HAL库驱动包中的说明:补充:HAL库使用主线外设初始化外设使用。

qq_25218501的博客 1979

【无标题】STM32F767串口空闲中断+DMA实现不定帧长度的接收

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录前言一、配置串口与DMA二、空闲中断服务函数二.串口+DMA发送三、主函数总结 前言 提示:这里可以添加本文要记录的大概内容: 使用STM32F767实现串口空闲中断+DMA传输接收不定帧长度数据,以及当中可能遇到的错误总结 提示:以下是本篇文章正文内容,下面案例可供参考 一、配置串口与DMA //硬件模块配置可直接通过CUBEMX配置 void MX_USART1_UART_Init(void) { huart1.In.

qq_42589531的博客 1167

分发蛋糕(c++)

2 相邻的两个小伙伴贡献值更高贡献值更高的会获得更多的蛋糕。第二行为n个数分别表示每个人的贡献值,用空格隔开。第一行一个正整数n表示参加庆功会的小伙伴的人数。你能够帮他算一下最少最少需要多少块蛋糕吗?共一行为一个正整数s,表示最少的蛋糕数。1 每个小伙伴至少分到1个蛋糕。

SunArrebol的博客 672

Unity中实现FairyGUI弹窗背景模糊的3种方法对比(附完整代码)

本文详细对比了Unity中实现FairyGUI弹窗背景模糊的3种方法,包括FairyGUI原生滤镜方案、多摄像机混合渲染方案和渲染纹理动态混合方案。每种方法均附有完整代码示例,帮助开发者根据项目需求选择最佳方案,实现镜头虚化模糊效果,提升游戏UI的视觉沉浸感。

ff678的博客 230

CCF认证——201703-1分蛋糕(C++)

试题编号: 201703-1 试题名称: 分蛋糕 时间限制 : 1.0s 内存限制 : 256.0MB 问题描述: 问题描述    小明今天生日,他有n块蛋糕要分给朋友们吃,这n块蛋糕(编号为1到n)的重量分别为a1, a2, …, an。小明想分给每个朋友至少重量为k的蛋糕。小明的朋友们已经排好队准备领蛋糕,对于每个朋友,小明总是先...

imprincess的专栏 347

ZYNQ学习:PL端DDR3 读写测试

DDR SDRAM 的最大特点是双沿触发,即在时钟的上升沿和下降沿都能进行数据采集和发送,同样的工作时钟, DDR SDRAM 的读写速度可以比传统的 SDRAM 快一倍。本次实验使用的 DDR3 芯片是南亚的 NT5CC256M16ER-EKI, NT5CC256M16ER-EKI 的 bank 位宽为 3,行位宽为 15,列位宽为 10,所以它的地址大小等于 2^3*2^15*2^10(即 2^28=256M),数据位宽为 16bit,所以容量大小为 256M*16bit,也就是 512MByte。

shuidiQAQ的博客 3031

【TM1650】STM8S TM1650芯片控制程序

以下为.h文件: #ifndef __TM1650_I2C_H #define __TM1650_I2C_H #include "stm8s.h" #include "stm8s_gpio.h" #include "tim1.h" #include "usart2.h" #include &lt;iostm8s103f3.h&gt; #include &lt;intrinsics....

cxw312864660的博客 1万+

第十次ccf 分蛋糕

题目: 试题编号: 201703-1 试题名称: 分蛋糕 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述   小明今天生日,他有n块蛋糕要分给朋友们吃,这n块蛋糕(编号为1到n)的重量分别为a1, a2, …, an。小明想分给每个朋友至少重量为k的蛋糕。小明的朋友

xiaoli_nu的博客 2025

uniapp:解决微信小程序包体积超过2M的优化方案+详解分包问题,编译小程序体积大于2M不能上传和预览提示体积太大的处理教程,uniApp微信小程序主包过大问题如何解决(排查可疑点+分包+最小改动)

uniapp微信小程序开发,如何解决打包太大无法预览发布的问题,uniApp微信小程序包体积超过2M的优化方法,uni-app打包微信小程序主包超2M终极解决方案,使用uniapp开发微信小程序使用uni_modules导致主包文件过大,无法发布的解决方法,UniApp开发的微信小程序主包过大问题及解决方案 编译小程序时Node-modules被打入主包,小程序体积大于2M不能上传和预览,怎么处理,解决微信小程序主包太大问题,微信小程序中主包和分包过大,详解分包问题,uni-app 微信小程序发布时,主包超

✅ 精选推荐文章 5066

CCF认证 201703-1:分蛋糕(C++)

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int N=1000; int main() { int a[N],n,k,i,sum=0,m=0; ...

咸鱼4号 407

美团mtgsig 1.2算法分析

mtgsig1.2的一些算法总结

记录一些web逆向的过程 3498

华为OD机试双机位C卷-用户入网定期复评(C/C++/Py/Java/Js/Go)

华为OD机试(机考)双机位C卷 【用户入网定期复评】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【用户入网定期复评】。

qq_45776114的博客 834

分蛋糕(201703-1/CCF)———附带思路和完整代码

文章目录0 效果1 题目2 思路3 代码 0 效果 1 题目 2 思路 每次计算数输入值的累加值,如果大于等于k,则分蛋糕次数加1,特判最后一次输入,无论累加值是否满足大于等于k,分蛋糕次数都加1。 3 代码 #include<cstdio> int main(){ int n, k, sum = 0, ans = 0; scanf("%d%d", &n, &k); while(n--){ int num; scanf("%d", &num); su

韩江雪de 小屋 820

深度学习工具包 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")

【每日一题】2023百度之星-蛋糕划分(二分,前缀和,模拟) 保姆级教程

小度一共可以切 K刀,每一刀都是垂直或者水平的,现在小度想知道在切了 K刀之后,最重的一块蛋糕最轻的重量是多少。小度准备切一个蛋糕。这个蛋糕的大小为 N∗N,蛋糕每个部分的重量并不均匀。

m0_69478376的博客 635

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

vijos1020—切蛋糕

题目 方法:二分+dfs+剪枝 这方面的c++实现是第一次,脑子一片混沌,后来参照大神代码才明白。 附大神代码 二分最多满足几个嘴巴,相当于定了下界,再dfs验证。 关键是剪枝: 1.以最小的嘴累加,与蛋糕总和比较,找到最多能满足的嘴数,就是二分上边界。 2.dfs时记录当前浪费的蛋糕和,总蛋糕量-当前浪费的蛋糕和<当前二分的要满足的嘴大小和,

wangwangbu的博客 1382

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

CCF [201703-1] 分蛋糕(C++)

试题编号: 201703-1 试题名称: 分蛋糕 时间限制: 1.0s 内存限制: 256.0MB 问题描述:   小明今天生日,他有n块蛋糕要分给朋友们吃,这n块蛋糕(编号为1到n)的重量分别为a1, a2, …, an。小明想分给每个朋友至少重量为k的蛋糕。小明的朋友们已经排好队准备领蛋糕,对于每个朋友,小明总是先将自己手中编号最小的蛋糕分给他,当这个朋友所分得蛋糕的重量不到k时,再继续将剩下...

Silly2521的博客 616

CCF 201703-1 分蛋糕

问题描述 小明今天生日,他有n块蛋糕要分给朋友们吃,这n块蛋糕(编号为1到n)的重量分别为a1, a2, …, an。小明想分给每个朋友至少重量为k的蛋糕。小明的朋友们已经排好队准备领蛋糕,对于每个朋友,小明总是先将自己手中编号最小的蛋糕分给他,当这个朋友所分得蛋糕的重量不到k时,再继续将剩下的蛋糕中编号最小的给他,直到小明的蛋糕分完或者这个朋友分到的蛋糕的总重量大于等于k。   请问当小明的蛋...

weixin_44358208的博客 285

CSP认证201703-1 分蛋糕[C++题解]:遍历

刷题

阿正的梦工坊 581

CCF——分蛋糕(C++)

#CCF——分蛋糕(C++) 代码用上了队列,虽然不用也可以实现。。。

qq_40916628的博客 1098

CCF CSP 分蛋糕 C++

分蛋糕 #include<bits/stdc++.h> using namespace std; int main(){ int n,k; cin>>n>>k; int a[n]; int weight = 0; int cnt = 0; for(int i= 0; i < n; i++){ cin>>a[i]; weight += a[i]; if(weight >= k){ cnt++; weight =

Alfrank的博客 416

CCF CSP 201703-1 分蛋糕(C++ Vector)

#include <iostream> #include <vector> using namespace std; vector<int> v; int main() { int n,k; cin>>n>>k; int a; for(int i=0;i<n;i++){ cin>>a; v.push_back(a); } in.

weixin_43752106的博客 396

CCF认证201703-1分蛋糕

问题描述   小明今天生日,他有n块蛋糕要分给朋友们吃,这n块蛋糕(编号为1到n)的重量分别为a1, a2, …, an。小明想分给每个朋友至少重量为k的蛋糕。小明的朋友们已经排好队准备领蛋糕,对于每个朋友,小明总是先将自己手中编号最小的蛋糕分给他,当这个朋友所分得蛋糕的重量不到k时,再继续将剩下的蛋糕中编号最小的给他,直到小明的蛋糕分完或者这个朋友分到的蛋糕的总重量大于等于k。   请问当小明的蛋糕分完时,总共有多少个朋友分到了蛋糕。 输入格式   输入的第一行包含了两个整数n, k,意义如上所述。   

weixin_43840211的博客 210
上一篇: CCF 201709-1 打酱油 C++ easy
下一篇: CCF 201709-2 公共钥匙盒 C++ not easy
cloudless_sky
博客等级 码龄8年 106粉丝 128原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值