bzoj1639 / P2884 [USACO07MAR]每月的费用Monthly Expense
P2884 [USACO07MAR]每月的费用Monthly Expense
二分经典题
二分每个段的限制花费,顺便统计下最大段
注意可以分空段
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int max(int &a,int &b){return a>b?a:b;}
#define N 100001
int a[N],n,m,ans=2e9;
bool check(int lim){
int st=,tot=,mxd=;
for(int i=;i<=n;++i){
if(a[i]>lim) return ;
if(tot+a[i]>lim)
++st,mxd=max(mxd,tot),tot=;
tot+=a[i];
}++st;
mxd=max(mxd,tot);
if(st<=m) ans=min(ans,mxd);//顺便统计最大段的最小花费
return st<=m;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i) scanf("%d",&a[i]);
int l=,r=1e9+;//二分限制花费
while(l<r){
int mid=l+(r-l)/;
if(check(mid)) r=mid;
else l=mid+;
}printf("%d",ans);
return ;
}
bzoj1639 / P2884 [USACO07MAR]每月的费用Monthly Expense的更多相关文章
- 洛谷—— P2884 [USACO07MAR]每月的费用Monthly Expense
https://www.luogu.org/problemnew/show/P2884 题目描述 Farmer John is an astounding accounting wizard and ...
- P2884 [USACO07MAR]每月的费用Monthly Expense
题目描述 Farmer John is an astounding accounting wizard and has realized he might run out of money to ru ...
- [USACO07MAR]每月的费用Monthly Expense
题目:POJ3273.洛谷P2884. 题目大意:有n个数,要分成m份,每份的和要尽可能小,求这个情况下和最大的一份的和. 解题思路:二分答案,对每个答案进行贪心判断,如果最后得出份数>m,则说 ...
- BZOJ1639: [Usaco2007 Mar]Monthly Expense 月度开支
1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 529 Solved: ...
- POJ-3273 Monthly Expense (最大值最小化问题)
/* Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10757 Accepted: 4390 D ...
- BZOJ【1639】: [Usaco2007 Mar]Monthly Expense 月度开支
1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 700 Solved: ...
- POJ3273 Monthly Expense —— 二分
题目链接:http://poj.org/problem?id=3273 Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 【POJ 3273】 Monthly Expense (二分)
[POJ 3273] Monthly Expense (二分) 一个农民有块地 他列了个计划表 每天要花多少钱管理 但他想用m个月来管理 就想把这个计划表切割成m个月来完毕 想知道每一个月最少花费多少 ...
- Divide and Conquer:Monthly Expense(POJ 3273)
Monthly Expense 题目大意:不废话,最小化最大值 还是直接套模板,不过这次要注意,是最小化最大值,而不是最大化最小值,判断的时候要注意 联动3258 #include <iostr ...
随机推荐
- opencv学习网站
强烈推荐一个老外的网站,pyimagesearch 网址:https://www.pyimagesearch.com/
- POJ_3186_Treats for the Cows
Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6568 Accepted: 34 ...
- Unified Modeling Language
https://en.wikipedia.org/wiki/Unified_Modeling_Language
- tomcat与jetty的区别
转载自:https://www.cnblogs.com/fengli9998/p/7247559.html Jetty和Tomcat为目前全球范围内最著名的两款开源的webserver/servlet ...
- json数据处理:读取文件中的json字符串,转为python字典
方法1: 读取文件中的json字符串, 再用json.loads转为python字典 import json str_file = './960x540/config.json' with open( ...
- Shell初学(二)变量及数组
精简版: 定义:your_name=123 PS:=符号左右不能有空格! 使用:${your_name},单独使用变量时可以不加{} 只读:readonly your_name PS:设置 ...
- [py][mx]django邮箱注册的验证码部分-django-simple-captcha库使用
邮箱注册-验证码 验证码使用第三方库django-simple-captcha 这个安装图形插件步骤官网有哦 - 1.Install django-simple-captcha via pip: pi ...
- hdu3339In Action(最短路+01背包)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, whe ...
- PAT 1018 Public Bike Management[难]
链接:https://www.nowcoder.com/questionTerminal/4b20ed271e864f06ab77a984e71c090f来源:牛客网PAT 1018 Public ...
- 从 Zero 到 Hero ,一文掌握 Python
译文:开源中国 www.oschina.net/translate/learning-python-from-zero-to-hero 第一个问题,什么是 Python ?根据 Python 之父 G ...