UVA12390/HDU4190 Distributing Ballot Boxes 二分答案
2012-08-04 19:51
459 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4190
题目大意:n个城市b个投票箱,每个城市的票分摊在投票箱里,问怎么放投票箱使得所有城市中最多的投票箱的票数最少。
解题思路:二分答案
代码:
题目大意:n个城市b个投票箱,每个城市的票分摊在投票箱里,问怎么放投票箱使得所有城市中最多的投票箱的票数最少。
解题思路:二分答案
代码:
#include <math.h> #include <stdio.h> #define MAX(x,y) ((x)>(y)? (x):(y)) using namespace std; int city[500100]; int main() { int n,b; while(scanf("%d%d",&n,&b)) { if(n==-1 && b==-1) break; int ans=-1; for(int i=1;i<=n;i++) { scanf("%d",&city[i]); ans=MAX(ans,city[i]); } int l=1,r=ans; while(l<r) { int temp=0; int mid=(l+r)/2; for(int i=1;i<=n;i++) { if(city[i]%mid) temp+=((int)((double)city[i]/(double)mid)+1); else temp+=city[i]/mid; } if(temp>b) l=mid+1; else r=mid; } printf("%d\n",l); } return 0; }
相关文章推荐
- hdu4190 Distributing Ballot Boxes(二分答案)
- HDU 4190 Distributing Ballot Boxes(二分答案)
- HDU 4190 Distributing Ballot Boxes【二分答案】
- {HDU}{4190}{Distributing Ballot Boxes}{二分答案}
- HDOJ题目4190 Distributing Ballot Boxes(二分搜索)
- 暑期集训—day1—hdu 4190— Distributing Ballot Boxes—二分,优先队列
- HDOJ 4190 Distributing Ballot Boxes(二分)
- HDOJ-4190-Distributing Ballot Boxes【二分】
- hdu 4190 Distributing Ballot Boxes (二分)
- Distributing Ballot Boxes(二分)
- 【二分枚举】杭电 hdu 4190 Distributing Ballot Boxes
- [UVA 11865]Stream My Contest[最小树形图][二分答案]
- UVALive 7500 Boxes and Balls (二分)
- UVALive 7500 Boxes and Balls 2015EC final 签到题 二分
- HDU - 4190 Distributing Ballot Boxes
- UVALive 3608 Period(二分答案+DP)
- HDU 4190 Distributing Ballot Boxes
- UVA11478 Halum 解题报告【图论】【二分答案】【SPFA】【差分约束系统】
- UVA 12124 - Assemble(二分答案)
- hdu 4190 Distributing Ballot Boxes(贪心+二分查找)