Codeforces--1283B--Candies Division

牛客网--14399--素数判断 题目描述: 给出一个数x,判断它是否为素数,并输出所有它的素因子。 输入描述: 第1行输入组数T,代表有T组数据。 第2-T+1行输入一个数x。 数据保证:2≤x≤109 输出描述: 每行输出两行,对应输入行的结果。 第1行,如果x是素数,输出“isprime”(不含双引号),否则输出“noprime”(不含双引号)。 第2行,输出x的素因子。 输入: 3 2 9 10 输出: isprime 2... 阅读详情

题目描述:
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can’t divide one candy into parts but he is allowed to not use some candies at all.

Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:

b−a≤1 (it means b=a or b=a+1);
the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k2⌋ (less than or equal to ⌊k2⌋).
⌊k2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k2⌋=⌊52⌋=2.

Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.

You have to answer t independent test cases.
输入描述:
The first line of the input contains one integer t (1≤t≤5⋅104) — the number of test cases.

The next t lines describe test cases. The i-th test case contains two integers n and k (1≤n,k≤109) — the number of candies and the number of kids.
输出描述:
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
输入:
5
5 2
19 4
12 7
6 2
100000 50010
输出:
5
18
10
6
75015
题意:
Santa要分糖,总共有n块糖,要分给k个小朋友,但要求分糖要满足以下条件:(设分完糖后小朋友得到最多糖的有b块,最少糖的有a块)b - a ≤ 1
糖数等于a+1的小朋友不能超过 floor(k/2) 个。其中 floor(k/2)为k/2向下取整。求在满足这样条件的情况下,Santa最多可以分出去多少块糖。
题解:
直接搞
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d%d",&n,&k);
        if(n % k == 0) printf("%d\n",n);
        else{
            int t = n / k;
            int ans = (t * k);
            ans += min(k / 2,n % k);
            printf("%d\n",ans);
        }
    }
    return 0;
}
Codeforces--1335A--Candies and Two Sisters 题目描述: There are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that: Alice will get a (a>0) candies; Betty will get b (b&g... 阅读详情

相关推荐

牛客--2019招商银行信用卡中心--跳格子游戏

题目描述: 假设你正在玩跳格子(所有格子排成一个纵列)游戏。需要 跳完n 个格子你才能抵达终点。 每次你可以跳 1 或 2 个格子。你有多少种不同的方法可以到达终点呢? 注意:给定 n 是一个正整数 输入描述: 格子数n 输出描述: 跳完n个格子到达终点的方法 输入: 2 输出: 2 题意: 题目描述 题解: 斐波拉切数列 代码: #include<cstdio> #include&l...

猩猩是个好程序员的博客 530

B. Candies Division

Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can’t divide one candy into parts but he is allowed to not use some ca...

atrapastul的博客 418

示波器学习(一):示波器的作用、类型和基本结构

示波器的作用、使用场景;示波器的类型和基本结构介绍

qq_41300605的博客 9146

Codeforces 1283B Candies Division

题目链接: Codeforces 1283B Candies Division 思路: 先使每个人糖果一样且尽可能用最多糖,然后再一个一个分派知道糖不够或者达到[k/2] 代码: #include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef long long ll; #d...

Yuhan的博客 542

Mac用户解决WPS中的俄语显示红线问题(WPS添加外语拼写检查)

我所使用的WPS版本:AppleStore 下载的 MacOs版 3.3.0 首先,对于 在访达-应用程序中,找到WPS,右键-点击“显示包内容” 然后按照下图的索引目录(Contents\Resource\office6\dicts\spellcheck),最后进入一个叫“spellcheck”的文件夹 最后将下载好的字典包(例如上图中的 en_US就代表美式英语;ru_RU就代表俄语) 关于字典包资源下载,我在网上找到一个Google云盘,里面包含了法语,德语,西语,意大利语,葡萄牙.

qq_48159150的博客 7914

FME入门系列教程3-带你玩转GIS数据搬运与处理

FME(Feature Manipulation Engine)就像GIS界的"瑞士军刀",它能轻松解决90%的数据处理难题。我最初接触FME是因为要处理200多个不同格式的CAD地形图,传统方法需要1周时间,用FME只花了2小时!:支持300+数据格式(Shapefile、GeoJSON、CAD、Excel等)添加Reader(数据源):选择示例数据roads.shp。添加Writer(输出):设置输出为GeoJSON格式。:将常用流程保存为Template(.fmwt)

weixin_41234946的博客 1253

Codeforces Round #611 (Div. 3) - BenFromHRBUST

A Minutes Before the New Year Problem Description New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows h hours and m minu...

BenFromHRBUST的CSDN博客 929

android 运动目标检测_MindSpore应用案例:AI对篮球运动员目标的检测

MindSpore作为一个端边云协同的开源的全场景AI框架,今年3月份开源以来,受到了业界的广泛关注和应用,欢迎大家参与开源贡献、模型众智合作、行业创新与应用、学术合作等,贡献您在云侧、端侧 (HiMindSpore 应用程序)、边侧以及安全领域的应用案例。MindSpore与您在AI领域共同成长,让AI使能千行百业,释放出强大的生产力。本文讲述的是MindSpore对篮球运动员目标的检测应用,通...

weixin_33603813的博客 837

A. Santa Claus and Candies

http://codeforces.com/problemset/problem/753/A time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Santa Claus hasncandies, he dream...

ccsu_deer 635

Plant Simulation数字孪生实战:从零搭建生产车间模型(附SimTalk脚本示例)

本文详细介绍了如何使用Plant Simulation从零构建生产车间数字孪生模型,包括基础建模、SimTalk脚本编程、参数化设计和高级应用。通过实战示例展示动态逻辑控制、设备故障模拟等关键技术,帮助工程师快速掌握数字孪生技术在制造业中的应用。

weixin_42527160的博客 363

国产系统迁移实战:在银河麒麟V10上搞定Wine32位支持,让老Windows软件跑起来

本文详细介绍了在银河麒麟V10操作系统上构建Wine32位支持的全过程,帮助用户解决Windows应用迁移难题。从系统架构差异分析到Wine环境配置,再到实战应用部署与优化,提供了一套完整的解决方案,确保老Windows软件在国产系统上稳定运行。

weixin_32288959的博客 663

【水题】Codeforce 1283B Candies Division

与上一道题一样,早起的水题醒盹。 一、题目大意 题目的大致意思是,Santa要分糖,总共有n块糖,要分给k个小朋友,但要求分糖要满足以下条件:(设分完糖后小朋友得到最多糖的有b块,最少糖的有a块) b - a ≤ 1 糖数等于a+1的小朋友不能超过 floor(k/2) 个。其中 floor(k/2)为k/2向下取整。 求在满足这样条件的情况下,Santa最多可以分出去多少块糖。 二、题目...

Johnson的博客 643

手把手教你学Simulink--电动物流车预充电路控制及主继电器粘连检测电机负载仿真

摘要:本文基于Simulink仿真平台,研究了电动物流车预充电路控制策略及主继电器粘连检测技术。通过构建预充电路、主继电器检测及电机负载模型,分析了不同工况下的系统特性。研究表明,优化的预充控制策略可缩短预充时间至0.5秒内,降低电流峰值;主继电器粘连检测模型能准确识别故障;电机负载变化对系统性能具有显著影响。仿真结果验证了所提方法的有效性,为提升电动物流车安全性与可靠性提供了理论支持和技术参考。

MHD0815的博客 65

Codeforces 1283 F DIY Garland ——想法

This way 题意: 现在有n个点,第i个点的权值为2i2^i2i,现在有n-1条边使得这些点组成一棵树,边的权值是它连接的子树的权值和。现在按照边的权值从大到小给你每条边的父节点,让你输出根节点的下标以及输出输入顺序每条边所连接的两个点 题解: 自顶向下我觉得做不了,但是反过来一想自底向上很简单,首先我们处理出所有未出现过的点是什么,然后最后一条边连接的一定是最小的那个点。有了这个思路我们就...

天翼之城的博客 316

【首发独家】华为OD机试 - 服务中心选址、服务中心的最佳位置(C 语言解题)

最近更新的博客 华为 od 2023 | 什么是华为 od,od 薪资待遇,od 机试题清单 华为 OD 机试真题大全,用 Python 解华为机试题 | 机试宝典 【华为 OD 机试】全流程解析+经验分享,题型分享,防作弊指南 华为 od 机试,独家整理 已参加机试人员的实战技巧 本篇华为 OD 机试题解:服务中心选址、服务中心的最佳位置

梦想橡皮擦,专栏100例写作模式先行者,现象级专栏 《Python 爬虫 100 例》作者、《滚雪球学 Python 专栏》原创者 1万+

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

753 A. Santa Claus and Candies

A. Santa Claus and Candies time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Santa Claus has n candies, he dreams to give them as gi...

小博客 663

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

【CF 1196A】Three Piles of Candies

A. Three Piles of Candies Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, ...

Xylon的博客 727

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

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

LeetCode575. Distribute Candies

Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these

郭小喜的博客 523

Codeforces 1283C Friends and Gifts

题目链接: Codeforces 1283C Friends and Gifts 思路: 将还没有分配的人和还没有被分配的人分别存进两个数组,挨个遍历,如果相同位置是同一个人,就和下一个交换 代码: #include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef long l...

Yuhan的博客 1429

cf1056B. Divide Candies(数论 剩余系)

题意 题目链接 求满足\(i^2 + j^2 \% M = 0\)的数对\((i, j)\)的个数,\(1 \leqslant i, j \leqslant 10^9, M \leqslant 1000\) Sol 发这篇博客的目的就是为了证明一下我到底有多菜。 mdzz小学组水题我想了40min都没想出来。这要是出在NOIP 2019的话估计我又要做不出Day1T1了。。 \(i^2 + j^2...

weixin_34128411的博客 197

Codeforces 1283D Christmas Trees(BFS)

题目链接: Codeforces 1283D Christmas Trees 思路: 直接BFS即可,先将距离圣诞树为1的点都加进队列,在pop距离为1的点时又可以加入距离为2的点…依次操作直到找到m个点; 用map来存储某个点是否被占用、以及离树的最短距离; 不要使用unordered_map,虽然u_map一般情况效率很高,但是遇到一些特殊情况效率反而比map低很多,具体原因参考这篇bl...

Yuhan的博客 764

Codeforces--664A--Complicated GCD

题目描述: Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to fi...

猩猩是个好程序员的博客 793

牛客网--204017--大吉大利

题目描述: 给定n个整数,依次为a1,a2,…,an。 求∑i=1n∑j=1n(ai&aj),&是二进制的与运算符。 输入描述: 第一行一个整数n. 第二行n个整数ai 输出描述: 一个整数表示上述求和式的答案. 输入: 5 1 2 3 4 5 输出: 33 题意: 题目描述 题解: 换成二进制运算 代码: #include<cstdio> #include<cs...

猩猩是个好程序员的博客 570

Codeforces--50A--Domino piling

题目描述: You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to plac...

猩猩是个好程序员的博客 545

牛客网--15735--小P和小Q

题目描述: 小P和小Q是好朋友,今天他们一起玩一个有趣的游戏。 他们的初始积分都为1,赢的人可以将自己的分数乘以 (K的平方),而输的人也能乘以K。 他们玩的太开心了,以至于忘了自己玩了多久,甚至 K 是多少和游戏进行的回合数 N 都忘了。 现在给出他们俩最终的积分a,b,请问是否存在正整数K、N满足这样的积分,判断他们的游戏结果是否可信。 输入描述: 第一行输入一个整数T(表示样例个数) 接下来...

猩猩是个好程序员的博客 469
上一篇: Codeforces--519C--A and B and Team Training
下一篇: Codeforces--318A--Even Odds
Ypopstar
博客等级 码龄11年 23粉丝 537原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值