Distributing Ballot Boxes

http://acm.hdu.edu.cn/showproblem.php?pid=4190

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

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 first 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 first 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
 
Source
 #include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<queue>
#include<map>
#include<stack>
typedef long long ll;
using namespace std; ll n,b;
ll a[]; bool erfen(ll mid){
ll sum=;
for(int i=;i<=n;i++){
sum+=int(ceil(a[i]*1.0/mid));
}
if(sum>b) return false;
return true;
} int main(){ while(cin>>n>>b){
if(n==-&&b==-) break;
ll L=,R=5e8;
ll mid;
for(int i=;i<=n;i++){
cin>>a[i];
}
while(L<=R){
mid=L+R>>;
if(erfen(mid)){
R=mid-;
}
else{
L=mid+;
}
}
cout<<L<<endl;
} }

Distributing Ballot Boxes的更多相关文章

  1. hdu 4190 Distributing Ballot Boxes 二分

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

  2. hdu 4190 Distributing Ballot Boxes(贪心+二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...

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

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

  4. Fedora 24 Gnome Boxes 无法ping通网络

    安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名 ...

  5. Problem B Boxes in a Line

     省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...

  6. Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s

    C. Inna and Candy Boxes   Inna loves sweets very much. She has n closed present boxes lines up in a ...

  7. boxes

    boxes [英][bɒksɪz][美][bɑ:ksɪz] n.盒( box的名词复数 ); 一盒; 电视; 小亭; v.把…装入盒[箱,匣]中( box的第三人称单数 ); 拳击;   以上结果来自 ...

  8. Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)

    B. Candy Boxes Problem's Link:   http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...

  9. UVa 103 - Stacking Boxes(dp求解)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

随机推荐

  1. dubbo 官方参考手册~备案(防止哪天阿里一生气把dubbo给删除了)

          首页  ||  下载  ||  用户指南  ||  开发者指南  ||  管理员指南  ||  培训文档  ||  常见问题解答  ||  发布记录  ||  发展路线  ||  社区 E ...

  2. 详解UE4静态库与动态库的导入与使用

    转自:http://blog.csdn.net/u012999985/article/details/71554628 一.基本内容概述   最近做项目时经常看到build.cs文件,就想研究一下UE ...

  3. Scrapy爬取人人网

    Scrapy发送Post请求 防止爬虫被反主要有以下几个策略 动态设置User-Agent(随机切换User-Agent,模拟不同用户的浏览器信息) 禁用Cookies(也就是不启用cookies m ...

  4. 布尔值运算&集合

    示例:返回booleanli = [] li = {} li = () if not li: print(1) radiansdict.has_key(key) #如果键在字典dict里返回true, ...

  5. Helm 入门安装指南

    Helm 是 Kubernetes 生态系统中的一个软件包管理工具.本文将介绍 Helm 中的相关概念和基本工作原理,并通过一个具体的示例学习如何使用 Helm 打包.分发.安装.升级及回退 Kube ...

  6. 好用的 FTP 软件之 FileZilla 技巧教程

    FTP 软件之 FileZilla教程 使用教程参考:http://163.26.161.1/~yilinteacher/wwwict/flash/FileZilla.swf (1)如何设置传输完成后 ...

  7. c++官方文档-class

    #include <iostream> using namespace std; class Circle { double radius; public: Circle(double r ...

  8. oracle11gr2笔记(一)

    一,使用scoot用户被锁.解决办法:(http://ciiiso.blog.51cto.com/8779682/1432869/) 二,使用root用户登录系统无法sqlplus,提示说permis ...

  9. 记一次python爬虫实战,豆瓣电影Top250爬虫

    import requests from bs4 import BeautifulSoup import re import traceback def GetHtmlText(url): for i ...

  10. HTML5播放器 MediaElement.js 使用方法

    目前已经有很多html5播放器可以使用,使用html5播放器可以轻松的在页面中插入媒体视频,从而使我们的web页面变得更加丰富多彩,所以今 天向大家推荐一款非常优秀的html5播放器MediaElem ...