题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190

Distributing Ballot Boxes

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

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
 
 
题目大意:有n个城市,b个投票箱,接下去的是每个城市的人口数,最后输出每个投票箱的容量是多少。
题目思路:对投票数进行二分,然后对箱子数进行匹配,人口数除以箱子的容量就是城市分配的箱子数。
 
详见代码。
 #include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int main ()
{
int a[];
int n,b,ans,Max;
while (~scanf("%d%d",&n,&b))
{
if (n==-&&b==-)
break;
Max=;
for (int i=;i<n;i++)
{
scanf("%d",&a[i]);
if (Max<a[i])
Max=a[i];
}
int l=;
int r=Max;
int sum,mid;
while (r>=l)
{
sum=;
mid=(r+l)/;
for (int i=;i<n;i++)
{
sum+=ceil(a[i]*1.0/mid);
}
if (sum>b)
l=mid+;
else
r=mid-,ans=mid;
}
printf ("%d\n",ans);
}
return ;
}

hdu 4190 Distributing Ballot Boxes(贪心+二分查找)的更多相关文章

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

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

  2. hdu 4190 Distributing Ballot Boxes 二分

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

  3. Distributing Ballot Boxes

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

  4. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  5. Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找

    The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 second ...

  6. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分

    C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  7. Holedox Eating HDU - 4302 2012多校C 二分查找+树状数组/线段树优化

    题意 一个长度$n<=1e5$的数轴,$m<=1e5$个操作 有两种一些操作 $0$  $x$ 在$x$放一个食物 $1$ 一个虫子去吃最近的食物,如果有两个食物一样近,不转变方向的去吃 ...

  8. BZOJ2796[Poi2012]Fibonacci Representation——贪心+二分查找

    题目描述 给出一个正整数x,问x最少能由多少个Fibonacci数加减算出. 例如1070=987+89-5-1,因此x=1070时答案是4. 输入 第一行一个正整数q (q<=10),表示有q ...

  9. HDU 5265 pog loves szh II (二分查找)

    [题目链接]click here~~ [题目大意]在给定 的数组里选两个数取模p的情况下和最大 [解题思路]: 思路见官方题解吧~~ 弱弱献上代码: Problem : 5265 ( pog love ...

随机推荐

  1. Thinkphp5使用validate实现验证功能

    作为前端er,对于验证这块有着切身的体会,虽然逐渐得心应手,但始终没有一个内置的功能拿来就能用.tp5恰好提供一个.本文简单介绍并实现以下.主要是实现一下. 验证的实现基于tp5内置的对象valida ...

  2. netem设置了网卡的流量控制,为啥发包的延迟就搞不定呢?

    为啥我用netem做了一个流量的控制 但是发送的时候,感觉真正发送数据的时候还是没有达到每一个数据包都是1s的延迟呀,这里的1s的延迟是啥意思啊? 这里的delay并不是说每个数据包都delay 5s ...

  3. 单点登录Windows实现

    Windows实现步骤: server.xml修改方式 hosts修改方式 CAS客户端配置 CAS配置filter.txt内容如下: <!-- ======================== ...

  4. 【转】c# 类反射简单操作

    转:http://www.jb51.net/article/25863.htm 首先建立一个测试的类  复制代码代码如下: public class MyClass { public int one ...

  5. 2017 ICPC beijing E - Cats and Fish

    #1631 : Cats and Fish 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU camp ...

  6. [BZOJ2055] 80人环游世世界

    Description ​ 想必大家都看过成龙大哥的<80天环游世界>,里面的紧张刺激的打斗场面一定给你留下了深刻的印象.现在就有这么 ​ 一个80人的团伙,也想来一次环游世界. ​ 他们 ...

  7. bzoj3709: [PA2014]Bohater 贪心

    ~~~题面~~~ 题解: 首先有一个比较明显的策略,肯定先要把能带给自己受益的先选完,然后再以最佳状态去打那些会给自己带来损失的怪. 对于前一部分(可以带来受益的怪),显然我们需要先从代价小的打起,因 ...

  8. [AHOI2009]最小割 最小割可行边&必须边

    ~~~题面~~~ 题解: 做这题的时候才知道有最小割可行边和必须边这种东西..... 1,最小割可行边, 意思就是最小割中可能出现的边. 充要条件: 1,满流 2,在残余网络中找不到x ---> ...

  9. BZOJ1046 [HAOI2007]上升序列 【LIS + 字典序最小】

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 5410  Solved: 1877 [Submit][St ...

  10. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...