二分搜索 POJ 3273 Monthly Expense
/*
题意:分成m个集合,使最大的集合值(求和)最小
二分搜索:二分集合大小,判断能否有m个集合。
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int n, m; bool check(int tot) {
int j = , sum = ;
for (int i=; i<=m; ++i) {
sum = ;
while (j <= n && sum + a[j] <= tot) {
sum += a[j++];
}
if (j == n + ) return true;
}
return false;
} int main(void) { //POJ 3273 Monthly Expense
//freopen ("POJ_3273.in", "r", stdin); while (scanf ("%d%d", &n, &m) == ) {
int l = , r = ;
for (int i=; i<=n; ++i) {
scanf ("%d", &a[i]);
if (l < a[i]) l = a[i];
r += a[i];
} while (l < r) {
int mid = (l + r) >> ;
if (check (mid)) r = mid;
else l = mid + ;
}
printf ("%d\n", l);
} return ;
}
二分搜索 POJ 3273 Monthly Expense的更多相关文章
- POJ 3273 Monthly Expense(二分查找+边界条件)
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...
- POJ 3273 Monthly Expense二分查找[最小化最大值问题]
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...
- [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14158 Accepted: 5697 ...
- POJ 3273 Monthly Expense(二分答案)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 36628 Accepted: 13620 Des ...
- poj 3273 Monthly Expense (二分搜索,最小化最大值)
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...
- POJ 3273 Monthly Expense(二分搜索)
Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...
- poj 3273 Monthly Expense(二分搜索之最大化最小值)
Description Farmer John ≤ moneyi ≤ ,) that he will need to spend each day over the next N ( ≤ N ≤ ,) ...
- poj 3273"Monthly Expense"(二分搜索+最小化最大值)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 天,第 i 天会有 a[ i ] 的花费: 将这 N 天分成 M 份,每 ...
- poj 3273 Monthly Expense(贪心+二分)
题目:http://poj.org/problem?id=3273 题意:把n个数分成m份,使每份的和尽量小,输出最大的那一个的和. 思路:二分枚举最大的和,时间复杂度为O(nlog(sum-max) ...
随机推荐
- CRT(secureCRT)中文显示研究&Linux中文字符显示
关于secureCRT设置编码: 基本上只需要设置crt字符编码与远程服务器一致就可以了.要注意的是,有时设置完之后要重启secureCRT, 不然不会生效.
- [NOIP2007] 普及组
奖学金 模拟 开个struct排序即可 c++吼啊 /*by SilverN*/ #include<algorithm> #include<iostream> #include ...
- Thinkphp5.0 的使用模型Model查询
Thinkphp5.0 的使用模型Model查询 一.查询多条记录 获取多个数据可以使用:select()方法和all()方法. 示例一:使用all()方法. //(1)筛选条件使用闭包函数 $res ...
- Uva - 11181 Probability|Given (条件概率)
设事件B为一共有r个人买了东西,设事件Ai为第i个人买了东西. 那么这个题目实际上就是求P(Ai|B),而P(Ai|B)=P(AiB)/P(B),其中P(AiB)表示事件Ai与事件B同时发生的概率,同 ...
- POJ3295 Tautology 解题报告
直接上分析: 首先 弄清各种大写字母的操作的实质 K 明显 是 and & A 是 or | N 是 not ! C 由表格注意到 当 w<=x 时 值为1 E 当 ...
- SQLServer2008 快捷键集合
CTRL + SHIFT + B 生成解决方案 CTRL + F7 ...
- Android GIS开发系列-- 入门季(9) 定位当前的位置
利用MapView定位当前的位置 这里要用到Arcgis中的LocationDisplayManager这个类,由于比较简单.直接上代码: LocationDisplayManager locatio ...
- 通过ambari安装hadoop集群
转载:http://www.cnblogs.com/cenyuhai/p/3295635.html 整个过程走完,问题不大,不过有一个事情要注意的是就算创建数据库的,使用localhost会报错,要使 ...
- 操作系统——IO管理
一.IO系统结构 在计算机系统中.cpu要和很多外设进行交互.比方鼠标,键盘,网卡等等. 1.IO是怎样协调工作的那? (1)对于设备来说,其有两部分组成,一部分是机械部分,还有一部分是电子控制部分. ...
- mysql复制延迟监控脚本
#!/bin/sh #ocpyang@126.com #repdelay.sh #查看复制延迟详细多少event #####1.juede the rep slave status export bl ...