Distributing Ballot Boxes

http://acm.hdu.edu.cn/showproblem.php?pid=4190

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2109    Accepted Submission(s): 1119

Problem Description
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 first 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 first 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 ai,(1<=ai<=5,000,000), indicating the population of the ith 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
 
Source
 #include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<queue>
#include<map>
#include<stack>
typedef long long ll;
using namespace std; ll n,b;
ll a[]; bool erfen(ll mid){
ll sum=;
for(int i=;i<=n;i++){
sum+=int(ceil(a[i]*1.0/mid));
}
if(sum>b) return false;
return true;
} int main(){ while(cin>>n>>b){
if(n==-&&b==-) break;
ll L=,R=5e8;
ll mid;
for(int i=;i<=n;i++){
cin>>a[i];
}
while(L<=R){
mid=L+R>>;
if(erfen(mid)){
R=mid-;
}
else{
L=mid+;
}
}
cout<<L<<endl;
} }

Distributing Ballot Boxes的更多相关文章

  1. hdu 4190 Distributing Ballot Boxes 二分

    Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. hdu 4190 Distributing Ballot Boxes(贪心+二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...

  3. HDU 4190 Distributing Ballot Boxes【二分答案】

    题意:给出n个城市,n个城市分别的居民,m个盒子,为了让每个人都投上票,问每个盒子应该装多少张票 二分盒子装的票数, 如果mid<=m,说明偏大了,r应该向下逼近 ,r=mid 如果mid> ...

  4. Fedora 24 Gnome Boxes 无法ping通网络

    安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名 ...

  5. Problem B Boxes in a Line

     省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...

  6. Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s

    C. Inna and Candy Boxes   Inna loves sweets very much. She has n closed present boxes lines up in a ...

  7. boxes

    boxes [英][bɒksɪz][美][bɑ:ksɪz] n.盒( box的名词复数 ); 一盒; 电视; 小亭; v.把…装入盒[箱,匣]中( box的第三人称单数 ); 拳击;   以上结果来自 ...

  8. Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)

    B. Candy Boxes Problem's Link:   http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...

  9. UVa 103 - Stacking Boxes(dp求解)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

随机推荐

  1. Makefile | Linux嵌入式编程 使用详细图解

    针对的是对Makefile一点都不会的小白哦! 练习之前我们要做好准备: (1):第一步创建一个目录,因为实验过程中生成的文件会很多,不要把你系统里的文件搞得乱七八糟. [cjj@bogon ~]$ ...

  2. img atl和a title

    今天发现一个有趣的现象.   <a href="#" title="a"><img src="xxx.jpg" alt=& ...

  3. python3 tkinter

    https://morvanzhou.github.io/tutorials/python-basic/tkinter/ 李导师推荐的.非常感谢.非常棒的视频教程!!! 只不过里面的教程视频是yout ...

  4. CorelDRAW X4常用快捷键大全

    材料/工具 CorelDRAW X4 方法 1 F1:帮助信息 F2:缩小 F3:放大 F4:缩放到将所有对象置于窗口中 F5:手绘(Freehand)工具 F6:矩形(Rectangle)工具 F7 ...

  5. Spark学习笔记1:Spark概览

    Spark是一个用来实现快速而通用的集群计算的平台. Spark项目包含多个紧密集成的组件.Spark的核心是一个对由很多计算任务组成的,运行在多个工作机器或者是一个计算集群上的应用进行调度,分发以及 ...

  6. hive的安装,一般不容易察觉的hdfs的配置问题导致hive安装的失败

    在安装hive的过程中,一般需要的准备环境就是hadoop集群的正常启动,要装有mysql,zookeeper. 具体怎么安装配置我在这里不多说,安装教程网上有挺多的. 我这里说下我遇到的问题,首先从 ...

  7. blktrace分析IO

    http://bean-li.github.io/blktrace-to-report/ 前言 上篇博客介绍了iostat的一些输出,这篇介绍blktrace这个神器.上一节介绍iostat的时候,我 ...

  8. 使用 xhprof 进行性能分析

        xhprof 是 facebook 开发的一个PHP扩展,作用来是用来做性能剖析.其官网:http://pecl.php.net/package/xhprof   [安装] 1,下载最新的 t ...

  9. serializers 序列化器里面进行 校验等

    一.第一版(一般不用) # 声明序列化器from rest_framework import serializersfrom djangoDome.models import Book class P ...

  10. 关于QT中“崩溃”问题

    经常会遇到一个问题,程序运行崩溃! 1.release.debug直接运行崩溃. 2.程序可以运行但是点击界面崩溃. 3.debug模式崩溃,release正常. 4.软件里面的release和deb ...