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. sql注入原理详解(一)

    我们围绕以下几个方面来看这个问题: 1.什么是sql注入? 2.为什么要sql注入? 3.怎样sql注入? 1.什么是sql注入? 所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或 ...

  2. ArrayList 和 Vector 的区别

    这两个类都实现了 List 接口( List 接口继承了 Collection 接口),他们都是有序集合,即存储在这两个集合中的元素的位置都是有顺序的,相当于一种动态的数组,我们以后可以按位置索引号取 ...

  3. oracle中将number类型毫秒值转为时间类型

    在搞数据库时,发现有这样的一个字段,类型是NUMBER(38),查看了一下里面的数据,都是这样的: 13239576781141321326994295132212930680413221297162 ...

  4. 微信小程序ofo小黄车+thinkphp5.0打造全栈应用

    原文地址:https://www.imooc.com/article/20310 ofo至今还没有微信小程序(很费解),每次用ofo都得去支付宝,很不方便,我用微信用的比较多,无意间在简书上面看到某人 ...

  5. Hibernate中连接数据库的配置

    Hibernate连接数据库的配置 实体类的映射文件 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mappin ...

  6. 架构师养成记--23.sigar使用实例

    作用是检测机器的硬件环境 注意在jdk的bin目录下加上sigar的lib目录中的文件 import java.net.InetAddress; import java.net.UnknownHost ...

  7. 4、TensorFlow基础(二)常用API与变量作用域

    1.图.操作和张量 TensorFlow 的计算表现为数据流图,所以 tf.Graph 类中包含一系列表示计算的操作对象(tf.Operation),以及在操作之间流动的数据 — 张量对象(tf.Te ...

  8. Codeforces - 149D 不错的区间DP

    题意:有一个字符串 s. 这个字符串是一个完全匹配的括号序列.在这个完全匹配的括号序列里,每个括号都有一个和它匹配的括号 你现在可以给这个匹配的括号序列中的括号染色,且有三个要求: 每个括号只有三种情 ...

  9. archlinux中gedit乱码的解决方法

    转自https://blog.csdn.net/oFAITH12345/article/details/24962545 例如:gedit key.c --encoding=GB18030 打开文件后 ...

  10. Spring整合Hibernate_数据源Datasource_dbcp连接池

    1,  Spring指定 datasource DataSource接口,在javax.sql包,里边有一个getConnection()方法.提供了标准化的取得连接的方式.只要实现了这个接口.Sun ...