题目:

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 a i,(1<=a i<=5,000,000), indicating the population of the i th 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
5000004 6
120
2680
3400
200-1 -1

Sample Output

100000
1700

题意:

有N个城市,M个投票箱。

然后是N行,表示每个城市的人口数。

现在每个城市所有的人要投票,投票箱的大小可以无限大(投票箱全部相同,大小相等),我们现在要求的是最小的投票箱容纳量。

思路:

如果N == M,则容量肯定为城市人口数最多的那个。

如果N<M,那么我们肯定要把所有的箱子都用上,这样最后箱子的最小容量才会是最小的,这样我们可以用二分法来判断箱子的最小容量。

代码如下:

#include<stdio.h>
#include<string.h>int a[500000];
int main()
{int c,b;while(scanf("%d%d",&c,&b)!=EOF){int i,max=0;if(c==-1||b==-1)break;for(i=0; i<c; i++){scanf("%d",&a[i]);if(a[i]>max)max=a[i];//存储最大的城市人数;}if(c==b)//箱子和城市个数相同,那么箱子的容量就应该是最大的人数;{printf("%d\n",max);continue;}int l,r,mid;l=1;r=max;while(l<r){int flag=0;int sum=0;mid=(l+r)/2;//这是箱子容量的中间值;for(i=0; i<c; i++){   //假设箱子的容量是mid;int tt;tt=a[i]%mid;if(tt==0)sum+=a[i]/mid;elsesum+=a[i]/mid+1;if(sum>b)   //如果箱子的容量是mid,但是所需要的箱子的个数小于原来的,这就意味着箱子的容量还可以增加;flag=1;}if(flag==1)//如果所需要的箱子数大于原来的数量,那么,箱子的数量应该小于mid;l=mid+1;else//如果所需要的箱子数小于原来的数量,那么,箱子的数量应该大于mid;r=mid;}printf("%d\n",r);}return 0;
}

B - Distributing Ballot Boxes相关推荐

  1. Distributing Ballot Boxes HDU - 4190

    问题·: Today, besides SWERC'11, another important event is taking place in Spain which rivals it in im ...

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

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

  3. 二分查找(折半查找)详解

    二分查找详解 1. 二分查找的引入 2. 二分的一些基本知识 1) 定义 2) 特点 3. 二分查找的边界问题 1) 常用模板 2)综合练习 4.二分的应用 1) Flyer 2) Distribut ...

  4. 马丁 路德 金的演讲词 I have a dream

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 马丁·路 ...

  5. 马丁路德金博士的三段演讲录音

    1.Our God Is Marching On! - 25 March 1965 在线收听 Let us therefore continue our triumphant march (Uh hu ...

  6. Tripwire 配置 使用

    关于Tripwire的使用,在网上找到如下两个比较全的文章, 一开始找到这个,按照其所述去做,但是始终不太清楚,最终能建立database,但是在执行 tripwire --check时找不到tw.c ...

  7. Anchor Boxes示例实战

    Anchor Boxes示例实战 目标检测算法通常对输入图像中的大量区域进行采样,判断这些区域是否包含感兴趣的目标,并调整这些区域的边缘,以便更准确地预测目标的真实边界框.不同的模型可能使用不同的区域 ...

  8. 深度学习Anchor Boxes原理与实战技术

    深度学习Anchor Boxes原理与实战技术 目标检测算法通常对输入图像中的大量区域进行采样,判断这些区域是否包含感兴趣的目标,并调整这些区域的边缘,以便更准确地预测目标的地面真实边界框.不同的模型 ...

  9. 例题6-5 移动盒子(Boxes in a Line, UVa 12657)

    例题6-5 移动盒子(Boxes in a Line, UVa 12657) 双向链表(数组模拟) #include<iostream> #include<algorithm> ...

  10. Uva 10177 - (2/3/4)-D Sqr/Rects/Cubes/Boxes?

    Problem J (2/3/4)-D Sqr/Rects/Cubes/Boxes? Input: standard input Output: standard output Time Limit: ...

最新文章

  1. 字节跳动实习生提出实例分割新方法:性能超过何恺明Mask R-CNN
  2. 初步学习“C#枚举”
  3. 使用C#创建SQLite控制台应用程序
  4. “No operations defined in spec!”一文教你swagger如何扫描多个controller
  5. P5135-painting【组合数学】
  6. windows系统改装为linux系统_Linux怎么克隆系统?备份系统跟Windows系统有区别吗?...
  7. 哈希表(HashTable),哈希冲突的避免、解决
  8. js获取当前日期时间和其他操作
  9. 【AVR单片机】【Microchip Studio】01项目创建
  10. Photoshop CS2 9.0注册机和注册方法
  11. 移动定位业务之“Cell ID + RTT(小区识别+往返时间)”
  12. 线性代数 06 克莱默法则
  13. 庞贝古城千年废墟复活:VR模型与眼动追踪复现被火山灰掩埋的建筑
  14. c51数字钟c语言程序,51单片机电子时钟C语言程序
  15. Android逆向系列(一):初探Android逆向
  16. 人民币符号怎么打?美元符号怎么打?
  17. start.bat批处理文件
  18. LeetCode每日一题 1238.循环码排列
  19. 《孤尽班T31-01-架构理论笔记》
  20. nslookup默认服务器修改,Windows Server 2008 R2 域控服务器运行nslookup命令默认服务器显示 UnKnown...

热门文章

  1. Ubuntu 18.04 安装 php7.4 --enable-maintainer-zts
  2. QPushButton 实现保持按下效果
  3. R 中 facet_wrap() 和 facet_grid() 的区别
  4. 网易微专业高级前端开发工程师2022
  5. 远程服务器 检索{00024500-0000-0000-C000-000000000046}组件失败 80080005 服务器运行失败 解决方案
  6. 【深入理解多线程】 Moniter的实现原理(四)
  7. 所谓的成长就是认知升级-成长就是应付自如
  8. 记分牌调度算法实现java_动态调度算法:记分牌算法和tomasulo算法
  9. python数字及字母的分离_Python 分割文本使得 字母和数字 分开?
  10. 专家有料 | 李中文:美团软件成分安全分析(SCA)能力的建设与演进