hdu 4190 Distributing Ballot Boxes (二分)
来源:互联网 发布:手机撒谎软件安卓版 编辑:程序博客网 时间:2024/04/30 03:30
一看到题目中间的那句“minimizes the maximum number”就想到了二分法。。。一般这种“最大值最小” 和”最小值最大“都能二分搞!
ok(x)函数就是给定一个最大值x,挨个城市模拟分配box,维护每个box的人数不大于x,看能否在B个box内将其装好。
#include<cstdio>#include<algorithm>#include<iostream>using namespace std;int n, B, a[555555];bool ok(int x){ int num = B; for(int i=0; i<n; i++) { if(a[i] <= x) num--; else { int tmp = a[i]; while(tmp > 0) { tmp -= x; num--; } } } return num >= 0;}int main(){ while(scanf("%d%d", &n, &B) && n != -1 && B != -1) { int limit = 0; for(int i=0; i<n; i++) { scanf("%d", &a[i]); limit = max(limit, a[i]); } int L = 0, R = limit, M; while(L < R) { M = (L + R) >> 1; if(ok(M)) R = M; else L = M + 1; } printf("%d\n", R); }}
- HDU 4190 Distributing Ballot Boxes(二分答案)
- hdu 4190 Distributing Ballot Boxes (二分)
- HDU 4190 Distributing Ballot Boxes【二分答案】
- HDU 4190 - Distributing Ballot Boxes
- hdu 4190 Distributing Ballot Boxes
- HDU - 4190 Distributing Ballot Boxes
- HDU-4190-Distributing Ballot Boxes
- HDU 4190 Distributing Ballot Boxes
- hdu 4190 Distributing Ballot Boxes
- 【二分枚举】杭电 hdu 4190 Distributing Ballot Boxes
- hdu 4190 Distributing Ballot Boxes(贪心+二分查找)
- HDOJ 4190 Distributing Ballot Boxes(二分)
- HDOJ-4190-Distributing Ballot Boxes【二分】
- Distributing Ballot Boxes(二分)
- 暑期集训—day1—hdu 4190— Distributing Ballot Boxes—二分,优先队列
- HDOJ题目4190 Distributing Ballot Boxes(二分搜索)
- UVA12390/HDU4190 Distributing Ballot Boxes 二分答案
- hdu4190 Distributing Ballot Boxes(二分答案)
- 图片转二进制
- JNI初步
- 用sublime搭建基于GoSublime+gocode+MarGo的下载SublimeGO开发环境
- POJ_2421 Constructing Roads
- go语言的安装已经调试
- hdu 4190 Distributing Ballot Boxes (二分)
- mysql常用日期时间/数值函数
- 不使用*、/、+、-、%操作符求一个数的1/3
- OpenStack API快速入门
- Go开发工具
- 深入研究win32结构化异常处理(SEH总结篇)
- 我校在第四届"蓝桥杯"全国软件创业团队大赛初赛中取得佳绩
- 黑马程序员---初识IO流
- C++中const、volatile、mutable的用法