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. 如果你最近在考虑OCR的问题,请进来~~~

    本文主要是python方面各类ocr的api对比问题,至于app推荐几款:合合信息(扫面全能王),TextGrabber,白描等等等等 工作需要,搞文字识别技术,对比了几家 百度的OCR: #!/us ...

  2. h5 html5 模拟时钟 页面

    <!DOCTYPE html> <html><head><meta http-equiv="Content-Type" content=& ...

  3. 内核诊断(二)-- patch 和diff

    patch文件结构 生成patch文件 --diff命令 patch 使用 -- patch命令 3.1 打path 3.1撤销patch 使用举例 4.1 基本命令使用 4.2 内核打补丁 1. p ...

  4. LINQ入门教程之各种标准查询操作符(一)

    好久之前就想系统的学习下LINQ,好久之前…… 本篇文章主要介绍LINQ等的标准查询操作符,内容取自<LINQ高级编程>,后续还会介绍LINQ to XML ,LINQ to SQL. L ...

  5. MySql互为主从配置文件及配置方法

    # Example MySQL config file for medium systems. # # This is for a system with little memory (32M - 6 ...

  6. net与树莓派的情缘-安装与卸载MySql(五)

    安装MySql sudo apt-get install mysql-server 删除 mysql sudo apt-get autoremove --purge mysql-server-5.0s ...

  7. (转)ELK Stack 中文指南--性能优化

    https://www.bookstack.cn/read/ELKstack-guide-cn/elasticsearch-README.md https://blog.csdn.net/cjfeii ...

  8. Linux系统编程:文件I/O编程

    文件I/O操作在Linux编程时是经常会使用到的一个内容,通常可以把比较大的数据写到一个文件中来进行存储或者与其他进程进行数据传输,这样比写到一个全局数组或指针参数来实现还要方便好多. 一.文件常用操 ...

  9. 菜单根据菜单ID向下递归

    第一步:我们根据这个类定义数据库,并插入菜单数据 DROP TABLE IF EXISTS `jrbac_menu`; CREATE TABLE `jrbac_menu` ( `id` ) NOT N ...

  10. 【Ubuntu】命令记录

    cp 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中,就如同DOS下的copy命令一样,功能非常强大. 语法: cp [选项] 源文件或目录 目标文件或目录 说明:该命令把指定的源文件复制到目 ...