Distributing Ballot Boxes

Distributing Ballot Boxes(HDU1490) 给出n个城镇的人,m个投票箱,求出最小票箱容积,使得最快完成投票收集。 2,7 2000 5000 那么一个票箱装1000,7个票箱装满。 这道题是第二次写,两种思路,一种是二分答案,一种是优先队列。 方法一:二分答案 #include using namespace std; int a[500005]; int n,m,maxnum; int check(int x) { 阅读详情

题目:

Today, besides SWERC'11, another important event is taking place in Spain which rivals it in importance: General Elections. Every single resident of the country aged 18 or over is asked to vote in order to choose representatives for the Congress of Deputies and the Senate. You do not need to worry that all judges will suddenly run away from their supervising duties, as voting is not compulsory. 
The administration has a number of ballot boxes, those used in past elections. Unfortunately, the person in charge of the distribution of boxes among cities was dismissed a few months ago due to nancial restraints. As a consequence, the assignment of boxes to cities and the lists of people that must vote in each of them is arguably not the best. Your task is to show how efficiently this task could have been done. 
The only rule in the assignment of ballot boxes to cities is that every city must be assigned at least one box. Each person must vote in the box to which he/she has been previously assigned. Your goal is to obtain a distribution which minimizes the maximum number of people assigned to vote in one box. 
In the first case of the sample input, two boxes go to the fi rst city and the rest to the second, and exactly 100,000 people are assigned to vote in each of the (huge!) boxes in the most efficient distribution. In the second case, 1,2,2 and 1 ballot boxes are assigned to the cities and 1,700 people from the third city will be called to vote in each of the two boxes of their village, making these boxes the most crowded of all in the optimal assignment.

Input

The fi rst line of each test case contains the integers N (1<=N<=500,000), the number of cities, and B(N<=B<=2,000,000), the number of ballot boxes. Each of the following N lines contains an integer a i,(1<=a i<=5,000,000), indicating the population of the i th city. 
A single blank line will be included after each case. The last line of the input will contain -1 -1 and should not be processed.

Output

For each case, your program should output a single integer, the maximum number of people assigned to one box in the most efficient assignment.

Sample Input

2 7
200000
500000

4 6
120
2680
3400
200

-1 -1

Sample Output

100000
1700

 

题意:

给出n个城市,每个城市有ai个人,总共有b个投票箱,每个城市最少有一个投票箱;

问投票箱最多使用人数的最小值;

 

思路:

二分法;

如果N = M,则容量为城市人口数最多的那个;

如果N < M,我们要把M全部用光,因为用的箱子越多,平均值越小;

所以,我们就可以二分枚举人口数作为投票箱的容量;

如果对于当前容量,我们枚举所有城市需要的箱子数目小于需要的箱子,就说明还可以再小;

如果需要的箱子数大于给出的箱子数,说明最小容量就在当前容量+1到刚才/2的容量数;

 

代码:

#include<stdio.h>
#include<math.h>
int a[10086111];
int n,m;
int cher(int x)
{
    int cost=0;
    for(int i=0;i<n;i++)
        cost+=ceil(a[i]*1.0/x);
    if(cost>m) return 0;
    else return 1;
}
void fen(int low,int high)
{
    int mid;
    while(low<high)
    {
        mid=(low+high)/2;
        if(cher(mid)==0)
            low=mid+1;
        else high=mid;
    }
    printf("%d\n",high);
}

int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        if(n==-1&&m==-1)
           break;
        int maxx=-10;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            if(a[i]>maxx)
                maxx=a[i];
        }
        fen(1,maxx);
    }
    return 0;
}

 

hdu 4190 #二分答案 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.Q Hand In Hand Online Acmers Forum | Discuss Statistical Charts Problem Archive Realtime Judge Statu 阅读详情

相关推荐

[0352]基于JAVA的停车场收费智慧管理系统的设计与实现

其次,从经营管理层面考虑,本系统涵盖了丰富的月卡管理和财务结算功能,如月卡用户管理、缴费、注销、挂失、解挂、补办等全流程服务,以及临保和月保的结算汇总与欠费查询等功能,这不仅有助于规范停车场的日常运营管理,更能有效提高财务管理效率,降低运营成本,实现精细化、数字化的财务管控。综上所述,本课题计划研发的基于Java的停车场收费智慧管理系统将在现有研究成果的基础上,重点优化月卡用户全生命周期管理和财务统计分析功能,以满足现代停车场高效、精准、安全的管理需求,紧跟行业发展趋势,为推动智慧城市的建设贡献一份力量。

muyu2980的专栏 589

Distributing Ballot Boxes HDU - 4190【详细翻译】【贪心、二分】

    题意:题目给出N个城市和B个邮箱,接下里输入N个城市的人口数量,对于每一个城市,需要给出至少一个邮箱方便选民寄信,我们所要做的就是,将邮箱按照一定要求分配给各个城市,使得装有最多信封的邮箱中的信封同比其他方案下最多信封的邮箱中的信封数是最少的(有那么点绕,简而言之就是相当于使得最大值最小)。    思路还是很明确的,跟Pie的那道题(我的解题链接(详解))差不多,在这里,我还是会给出详解:...

既然弱小,就只顾变强就是了 448

BMW Trojan 样本分析

仅用于链接已经删却但是需要方便查阅的原文http://blog.youkuaiyun.com/zirconsdu/article/details/7997470 转载请注明出处http://blog.youkuaiyun.com/zirconsdu/article/details/8153813。 一些具体数据结构和具体路径隐去。   BMW木马样本分析 摘要 2011年底和某Hunter的谈话涉及到当时新检

zirconsdu的专栏 3911

hdu 4190 Distributing Ballot Boxes 二分

Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 756Accepted Submission(s): 372 Problem Description Today, bes...

weixin_33750452的博客 198

实战经验:Sensor Bringup中那些坑我都帮你踩过了(避坑指南)

本文是一份详尽的Sensor Bringup实战避坑指南,总结了从I2C通信、MCLK时钟、电源管理到图像异常等关键环节的常见问题与排查方法。文章提供了系统化的调试工作流,强调先硬件后软件的排查原则,旨在帮助硬件工程师快速定位并解决Sensor启动过程中的难题,提升开发效率。

weixin_29212429的博客 574

[面试]SoC验证工程师面试常见问题(三)

SoC 验证工程师面试中,SystemVerilog、UVM 和 SystemC 的代码题目通常涵盖面向对象编程、约束随机化、UVM 组件设计、内存建模等主题。通过练习上述示例题目和理解关键点,你可以更好地应对现场编码环节。如果有具体的面试方向(如特定协议验证)或公司偏好,可以提供更多信息,我会进一步定制题目和答案。祝你面试顺利!

元直的博客 1616

Distributing Ballot Boxes【HDU - 4190 】

Today, besides SWERC'11, another important event is taking place in Spain which rivals it in importance: General Elections. Every single resident of the country aged 18 or over is asked to vote in ord...

Meant_To_Be的博客 269

手把手教你打造CTF动态靶场

公司想搞一个CTF比赛,需要一个竞赛靶场,于是这个任务就落在了我的身上,平台是利用CTFd框架,基于docker搭建的动态靶场,搭建过程中遇到的坑比较多,这里我会把每一个遇到的坑都指出来。我搭建的是CTFd的3.X的版本。第一次搭建的话,搭建的过程会有些痛苦,但是搭建完成后会越来越熟练,这个平台的可用性还是很高的。由于搭建的过程中遇到的坑太多了,各种各样的问题,所以决定写下这篇文章,把所有的坑都指出来,也算为后边想搭这个平台的小伙伴指一条路。Taps:资源来源:星海安全实验室如果你也对网络安全&黑客。

Python栈 4934

Distributing Ballot Boxes HDU - 4190

Today, besides SWERC'11, another important event is taking place in Spain which rivals it in importance: General Elections. Every single resident of the country aged 18 or over is asked to vote in ord...

Qtt110的博客 200

大语言模型在建筑规范自动化合规审查中的微调策略与规模效应实践

大语言模型(LLM)通过在海量文本数据上预训练,具备了强大的语言理解和生成能力。其核心原理是基于Transformer架构,通过自注意力机制捕捉长距离依赖关系。在工程实践中,为了将这种通用能力适配到建筑、法律、金融等高度专业化的垂直领域,通常需要采用领域微调技术。微调通过使用特定领域的高质量指令数据对模型参数进行更新,使其掌握专业术语、逻辑规则和任务范式,从而解决通用模型在专业场景下知识匮乏和“幻觉”问题。结合检索增强生成(RAG)技术,将动态外部知识库作为模型的“参考手册”,能进一步提升事实准确性并降低幻

weixin_30667831的博客 362

基于Vivado2025的UltraScale+时序收敛优化实战案例

深入解析在Vivado2025环境中针对UltraScale+架构的时序收敛挑战,结合实际设计案例,分享关键优化策略与操作技巧,显著提升设计性能与收敛效率。vivado2025的更新特性为时序优化带来新机遇。

weixin_33660045的博客 343

Distributing Ballot boxes

Today, besides SWERC'11, another important event is taking place in Spain which rivals it in importance: General Elections. Every single resident of the country aged 18 or over is asked to vote in ord...

x2535723242的博客 171

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

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

HDU 4190 - Distributing Ballot Boxes

贪心+二分,最大值最小化问题。利用投票箱b的值是一定的,将投票数进行二分,使得算出的投票箱数始终为b。 代码如下: #include int city[500001]; int main() { int n, b; while(scanf("%d%d", &n, &b)) { int Max = 0, l, r, mid; if(n=

GooMaple 956

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

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

B - Distributing Ballot Boxes

题目: Today, besides SWERC'11, another important event is taking place in Spain which rivals it in importance: General Elections. Every single resident of the country aged 18 or over is asked to vote i...

titi2018815的博客 201

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

上一篇: Fire Net
下一篇: Maximum Sum
admin__
博客等级 码龄8年 3粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值