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. HDU 2063 过山车(匈牙利算法)

    过山车 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  2. ASP.NET Web Pages:表单

    ylbtech-.Net-ASP.NET Web Pages:表单 1.返回顶部 1. ASP.NET Web Pages - HTML 表单 表单是 HTML 文档中放置输入控件(文本框.复选框.单 ...

  3. CentOS 6.4 添加永久静态路由所有方法汇总(原创)

    转摘,原文章地址:http://blog.sina.com.cn/s/blog_828e50020101ern5.html 查看路由的命令route -n CentOS添加永久静态路由 在使用双网卡, ...

  4. [UE4]为UStaticMeshComponent添加点击事件

    BlockMesh->OnClicked.AddDynamic(this, &APuzzleBlock::BlockClicked); //鼠标点击事件 BlockMesh->On ...

  5. php实现AES/CBC/PKCS5Padding加密解密(又叫:对称加密)

    今天在做一个和java程序接口的架接,java那边需要我这边(PHP)对传过去的值进行AES对称加密,接口返回的结果也是加密过的(就要用到解密),然后试了很多办法,也一一对应了AES的key密钥值,偏 ...

  6. git log --author详解,这个是个模糊匹配

    git log --author=authorname --author=<pattern>, commits whose author matches any of the given ...

  7. mysql主从复制——双机互为主从

    第一.mysql主从复制(一主一从)怎么安装mysql数据库,这里不说了,只说它的主从复制,步骤如下:首先需要做一些清理工作,如果之前配置了主从,但是配置失败了.结果会在/var/lib/mysql/ ...

  8. 最简单的TCP、UDP案例及各函数的详细解释

    TCP: server #include "stdafx.h" #include<iostream> #define BUF_SZIE 64 #include &quo ...

  9. HTML5中常用的标签(及标签的属性和作用)

    1.标签:<!DOCTYPE>作用:声明是文档中的第一成分,位于<html>标签之前. 2.标签:<html>作用:此元素可告知浏览器其自身是一个HTML文档.属性 ...

  10. 37. CentOS-6.3安装配置Weblogic-10

    安装说明 安装环境:CentOS-6.3-x64软件:server1001_ccjk_linux32.bin安装方式:bin文件安装 安装位置:/usr/local/weblogic/下载地址:htt ...