Distributing Ballot Boxes

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

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 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 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
 
 /*
题意:给5*10^5个城市,每个城市的人口数目。由于投票需要箱子。
保证每个城市至少要一个箱子。
求 满足个数的前提下,箱子最少能容纳的投票数。
举例:
2 7 有2个城市,有7个箱子
50 20 城市人数分别为50 20.
此时如果对于箱子而已,1个箱子容纳10人,也满足个数条件。
1个箱子容纳10人,也满足个数条件。
但是取10. (满足个数的前提下,箱子最少能容纳的投票数。)
*/ #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; int a[],n,m;
int fun(int mid)
{
int i,num=;
for(i=;i<=n;i++)
{
if( a[i]%mid==)
num=num+a[i]/mid;
else num=num+a[i]/mid+;
}
return num;
} int EF(int l,int r,int num) //二分写得搓。
{
int mid,ans,ll=l,rr=r;
while(l<r)
{
mid=(l+r+)/;
ans=fun(mid);
if( ans<=num )
r=mid;
else
l=mid;
if( l==ll && r==rr) break;
else
{
ll=l;
rr=r;
}
}
if( fun(l)<=num) return l;
else return r;
}
int main()
{
int i;
int Max,k;
while(scanf("%d%d",&n,&m)>)
{
if( n==- && m==-)break;
for(i=,Max=-;i<=n;i++)
{
scanf("%d",&a[i]);
if( a[i]>Max ) Max=a[i];
}
k=EF(,Max,m);
printf("%d\n",k);
}
return ;
}

hdu 4190 Distributing Ballot Boxes 二分的更多相关文章

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

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

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

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

  3. Distributing Ballot Boxes

    Distributing Ballot Boxes http://acm.hdu.edu.cn/showproblem.php?pid=4190 Time Limit: 20000/10000 MS ...

  4. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  5. hdu 3433 A Task Process 二分+dp

    A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. HDU 3622 Bomb Game(二分+2-SAT)

    Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  8. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  9. HDU 2063 过山车(二分匹配入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

随机推荐

  1. 根据某个key给二维数组分组

    /** * 根据某个key给二维数组分组 */ private function array_group_by($arr, $key) { $grouped = []; foreach ($arr a ...

  2. [转] YUM 源优先级插件:Yum Priorities

    Linux 发行版比较多,同时还有很多个人或组织维护了某些特定用途的安装/升级源.Yum Priorities 插件可以用来强制保护源.它通过给各个源设定不同的优先级,使得系统管理员可以将某些源(比如 ...

  3. 敏感词过滤的算法原理之 Aho-Corasick 算法

    参考文档 http://www.hankcs.com/program/algorithm/implementation-and-analysis-of-aho-corasick-algorithm-i ...

  4. Google 里的软件工程学

    简评:原文作者 Fergus Henderson 在 Google 工作了 10 年以上,目前负责 Google 的 text-tospeech 工程小组.有很多书籍或文章会从 商业/管理 等非技术角 ...

  5. 总结day04 ---- 列表的切片,增删改查,以及,相关方法, 元祖的使用方法

    内容大纲 1 : 列表的索引 : 列表的切片 2 : 列表的增加内容 >1:append(char)  >2:insert(index,char) >3:extend('可迭代对象' ...

  6. 总结day1 ---- 基础内容学习 ,以及历史了解

    知识目录 一 : python 的发展历史 1. pyhton2 和pyhton3 的区别 二: python的语言分类 三 :变量 四: 常量 五 :注释 六 : 基本数据类型 1 : int 2 ...

  7. Centos7.4下安装Mysql8.0.15

    一.下载Mysql Mysql下载地址:https://dev.mysql.com/downloads/mysql/ 二.卸载Linux自带的mariadb    安装Mysql之前需要卸载maria ...

  8. Unity脚本生命周期与执行顺序

    文章目录 脚本生命周期 MonoBehavior生命周期图 脚本执行顺序 自定义执行顺序 在Unity中,脚本可以理解为附加在游戏对象上的用于定义游戏对象行为的指令代码.必须绑定在游戏对象上才能开始它 ...

  9. C++ class和struct的区别

    class和struct定义类唯一的区别就是默认的访问权限. 如果我们使用struct关键字,则定义在第一个访问说明符之前的成员是public的:相反,如果我们使用class关键字,组这些成员是pri ...

  10. mysql数据库使用脚本实现分库备份过程

    一条命令解决分库分表备份: [root@db01 data]# mysql -uroot -p123456 -e "show databases;"|egrep -v " ...