hdu 4190 Distributing Ballot Boxes(贪心+二分查找)
题目链接: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
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.
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.
integer, the maximum number of people assigned to one box in the most efficient
assignment.
- #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(贪心+二分查找)的更多相关文章
- HDU 4190 Distributing Ballot Boxes【二分答案】
题意:给出n个城市,n个城市分别的居民,m个盒子,为了让每个人都投上票,问每个盒子应该装多少张票 二分盒子装的票数, 如果mid<=m,说明偏大了,r应该向下逼近 ,r=mid 如果mid> ...
- hdu 4190 Distributing Ballot Boxes 二分
Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Distributing Ballot Boxes
Distributing Ballot Boxes http://acm.hdu.edu.cn/showproblem.php?pid=4190 Time Limit: 20000/10000 MS ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- 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 ...
- 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/ ...
- Holedox Eating HDU - 4302 2012多校C 二分查找+树状数组/线段树优化
题意 一个长度$n<=1e5$的数轴,$m<=1e5$个操作 有两种一些操作 $0$ $x$ 在$x$放一个食物 $1$ 一个虫子去吃最近的食物,如果有两个食物一样近,不转变方向的去吃 ...
- BZOJ2796[Poi2012]Fibonacci Representation——贪心+二分查找
题目描述 给出一个正整数x,问x最少能由多少个Fibonacci数加减算出. 例如1070=987+89-5-1,因此x=1070时答案是4. 输入 第一行一个正整数q (q<=10),表示有q ...
- HDU 5265 pog loves szh II (二分查找)
[题目链接]click here~~ [题目大意]在给定 的数组里选两个数取模p的情况下和最大 [解题思路]: 思路见官方题解吧~~ 弱弱献上代码: Problem : 5265 ( pog love ...
随机推荐
- SPDY以及HTTP2.0
背景介绍 HTTP2.0跟SPDY在不少理念上是相似的,目的都是为了提升HTTP1.1的性能. HTTP2.0将会是业界的标准,比SPDY要完善,今后可能会都转向http2.0而放弃SPDY. SPD ...
- docker中crontab无法运行
yum install -y crontabssed -ri 's/.*pam_loginuid.so/#&/' /etc/pam.d/crond vi /etc/pam.d/crond ...
- java 基础--数组--004
1,数组定义格式 String[] aa; String aa[];2,二位数组的定义格式1 String aa[][] = new String[m][n]; String[] aa[] = new ...
- java 基础 --int 和Integer的区别
感到脸红:int是整形 -128~127 Integer是正整型,你怎么会想到这样的回答,妈的,有脑子吗?!!! 1,int是基本数据类型,初始为0,Integer为封装类,初始为null ①无论如何 ...
- GC是什么?为什么要有GC
GC:Garbage Collection 垃圾收集器. GC就是对“不可达“的对象进行回收,释放内存. Java内存的管理实际上就是对对象的管理,其中包括对对象的分配和回收. 对于程序员来说,分配对 ...
- [C/C++] 字符串错题集
1. 答案:A 这里考查转义字符,注意 \\ 表示字符 \\123表示字符 {\t 表示制表符这些都是一个字符. 2. 答案C 先不看有没有重复的,共5个字母,有5×4×3×2×1 = 120种组合. ...
- java 中 Stringbuff append源代码浅析
public synchronized StringBuffer append(String str) { super.append(str); return this; ...
- 转:Simple Introduction to Dirichlet Process
来源:http://hi.baidu.com/vyfrcemnsnbgxyd/item/2f10ecc3fc35597dced4f88b Dirichlet Process(DP)是一个很重要的统计模 ...
- 【刷题】洛谷 P3901 数列找不同
题目描述 现有数列 \(A_1,A_2,\cdots,A_N\) ,Q 个询问 \((L_i,R_i)\) , \(A_{Li} ,A_{Li+1},\cdots,A_{Ri}\) 是否互不相同 输入 ...
- 洛谷2219:[HAOI2007]修筑绿化带——题解
https://www.luogu.org/problemnew/show/P2219#sub 为了增添公园的景致,现在需要在公园中修筑一个花坛,同时在画坛四周修建一片绿化带,让花坛被绿化带围起来. ...