题目:

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. 使用绘图API自定义组件
  2. linux区分个系统脚本
  3. 亚马逊标题自动抓取_15分钟内开始使用Amazon Web Services和全自动资源调配
  4. 最小生成树Kruskal算法+并查集检查连通
  5. 遍历指定目录并且从子目录开始将目录输出到指定文件
  6. 眼睛-摄像 科技-文学
  7. 课后作业1:字串加密
  8. 【bzoj5166】[HAOI2014]遥感监测 贪心
  9. 逻辑回归案例模板——信用卡欺诈检测
  10. 已解决-电脑端HP Scan扫描无反应无法扫描
  11. kubernetes 网络组件 calico 运行原理分析
  12. 谷歌无法加载pdf文档_如何从Google文档文档创建PDF
  13. CJW精选题库(from 各种OJ)
  14. @staticmethod的粗浅认识
  15. 尚硅谷_springcloud(2020新版) 下载_异界删除浓缩怎么得|原创下载异界仙战游戏一次搞定 异界仙战安卓下载地址最新版整理...
  16. GUI 图形用户界面编程(十一)-扑克界面设计
  17. Android 横竖屏幕切换(layout-land和layout-port)
  18. 简单几行命令让pip升级
  19. 被黑客攻击最多的产业是那些呢?
  20. 陌陌前端面试 - 凉面

热门文章

  1. 【渝粤教育】国家开放大学2018年秋季 3939T★汽车电控技术 参考试题
  2. P3939 数颜色 动态开点线段树
  3. Layui 后台ajax 腾讯地图 多点标记mark
  4. vscode的插件prettier配置
  5. XP IIS之——问题总结
  6. 「实用工具—LICEcap」写博必备|动图制作|一键生成gif(GIF)
  7. Vivado 除法器IP核 小数模式(Fractional)下结果的修正
  8. 时钟系统和系统功耗的关系
  9. 中学计算机课体育课被占用,那些年被占用的体育课
  10. 51单片机【五】LED点阵屏