hdu 4190 Distributing Ballot Boxes 二分
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
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.
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.
/*
题意:给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 二分的更多相关文章
- hdu 4190 Distributing Ballot Boxes(贪心+二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...
- HDU 4190 Distributing Ballot Boxes【二分答案】
题意:给出n个城市,n个城市分别的居民,m个盒子,为了让每个人都投上票,问每个盒子应该装多少张票 二分盒子装的票数, 如果mid<=m,说明偏大了,r应该向下逼近 ,r=mid 如果mid> ...
- Distributing Ballot Boxes
Distributing Ballot Boxes http://acm.hdu.edu.cn/showproblem.php?pid=4190 Time Limit: 20000/10000 MS ...
- HDU 5810 Balls and Boxes(盒子与球)
Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 3622 Bomb Game(二分+2-SAT)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 5810 Balls and Boxes (找规律)
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- HDU 2063 过山车(二分匹配入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...
随机推荐
- ecshop后台0day漏洞原理+利用方法 XSS+Getshll
发布日期:2012-10.25 发布作者:dis9@ztz 漏洞类型:跨站攻击 代码执行 0x0 后台getshell 在 includes/cls_template.php fetch函数 /** ...
- 【bash】今天你坑队友了吗
需求: 压缩日志并删除压缩过的文件 很日常的运维需求!!! 好,来看代码 echo 'start' quke.log rm -f quke.log echo 'delete' 不管是初级运维还是高级运 ...
- mxonline实战11,课程详情页2,课程章节页
对应github地址:第11天 一. 课程详情页2 1. 课程详情页第2块中的课程介绍中,修改course-detail.html中代码,搜索课程详情,找到如下代码
- 手机APP测试点总结
一.功能性测试: (1)根据产品需求文档编写测试用例 (2)软件设计文档编写用例 二.兼容性适配性测试: (1)Android.iOS版本的兼容性 (2)手机分辨率兼容性 (3)网络的兼容性:2G/3 ...
- 总结day25 ---- udp 初识, 和tcp 进阶
前情提要 一: tcp 和udp 的区别 # tcp # # 面向连接的 可靠的 全双工的 流式传输 # # 面向连接 :同一时刻只能和一个客户端通信 # # 三次握手.四次挥手 # # 可靠的 :数 ...
- H01-Linux系统中搭建Hadoop和Spark集群
前言 1.操作系统:Centos7 2.安装时使用的是root用户.也可以用其他非root用户,非root的话要注意操作时的权限问题. 3.安装的Hadoop版本是2.6.5,Spark版本是2.2. ...
- 技巧方法 - CentOS6将Python2.6.6升级到Python2.7.6
1.首先使用“python -V”命令查看python版本,我们测试主机显示的是2.6.6版,于是下面就着手将python2.6.6升级到Python2.7.6.python -V #查看python ...
- js继承(自备水,这非常干货)
讲js继承之前,想一想什么是继承? 生活中有很多例子,比方说继承财产,继承女朋友的前男友的前女友 ヽ(ー_ー)ノ ,这些和js继承差不多,但是有一个不一样的地方,就是继承过后,原先的人就没有了,js继 ...
- pytest+jenkins安装+allure导出报告
环境安装: windows7+64位 pytest:4.0.2 allure的安装:allure的python库pytest-allure-adaptor jenkins的安装:2.138.2 JDK ...
- 20190417 CentOS 7下安装ActiveMQ
前言 用VMware安装CentOS 7.6,创建一个新的用户lihailin9073,并使用这个用户登陆CentOS系统 安装和启动 登陆ActivieMQ官网http://activemq.apa ...