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 ...
随机推荐
- c++中system("pause")的作用和含义
简单来说就是暂停的意思,一般在LINUX编程时会用到,等待接收信号,才会重新运行 . 在进行C/C++编程的时候,在运行程序查看输出效果时,会出现窗口闪一下就关闭的情况. 在C语言中一般通过添加get ...
- Scala学习笔记(2)-类型注意
Scala类型注意事项: 1.Any是绝对的根,所有的其他可实例化类型均有AnyVal和AnyRef派生. 2.所有AnyVal的类型成为值类型(所有数值类型.char.Booble和Unit) 3. ...
- HDU 3038 - How Many Answers Are Wrong - [经典带权并查集]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- Linux:发行版安装包的下载地址
1.Linux发行版网址 发行版 http://distrowatch.com Linux发行版信息大全 Ubuntu http://www.ubuntu.com 官网 http://cdimage. ...
- ubuntu x64 debootstrap
sudo debootstrap jessie /mnt/jessie http://mirrors.163.com/debian
- Golang 序列化方式及对比
Golang 序列化方式及对比 - fengfengdiandia的专栏 - CSDN博客 https://blog.csdn.net/fengfengdiandia/article/details/ ...
- C++中的类成员指针
写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...
- iOS多线程编程之NSThread的使用(转载)
1.简介: 1.1 iOS有三种多线程编程的技术,分别是: 1.NSThread 2.Cocoa NSOperation (iOS多线程编程之NSOperation和NSOperationQueue的 ...
- LoadRunner-迭代和并发设置
迭代:指运行一次脚本时某段代码块(action)循环执行的次数,串行执行 并发:指同时运行脚本的次数,并行执行(多个用户同时跑) 以下是用例和对应的相关设置 Iterations是在Vuser Gen ...
- Java学习之路-Spring的HttpInvoker学习
Hessian和Burlap都是基于HTTP的,他们都解决了RMI所头疼的防火墙渗透问题.但当传递过来的RPC消息中包含序列化对象时,RMI就完胜Hessian和Burlap了. 因为Hessian和 ...