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的更多相关文章

  1. 洛谷—— P2884 [USACO07MAR]每月的费用Monthly Expense

    https://www.luogu.org/problemnew/show/P2884 题目描述 Farmer John is an astounding accounting wizard and ...

  2. P2884 [USACO07MAR]每月的费用Monthly Expense

    题目描述 Farmer John is an astounding accounting wizard and has realized he might run out of money to ru ...

  3. [USACO07MAR]每月的费用Monthly Expense

    题目:POJ3273.洛谷P2884. 题目大意:有n个数,要分成m份,每份的和要尽可能小,求这个情况下和最大的一份的和. 解题思路:二分答案,对每个答案进行贪心判断,如果最后得出份数>m,则说 ...

  4. BZOJ1639: [Usaco2007 Mar]Monthly Expense 月度开支

    1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 529  Solved: ...

  5. POJ-3273 Monthly Expense (最大值最小化问题)

    /* Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10757 Accepted: 4390 D ...

  6. BZOJ【1639】: [Usaco2007 Mar]Monthly Expense 月度开支

    1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 700  Solved: ...

  7. POJ3273 Monthly Expense —— 二分

    题目链接:http://poj.org/problem?id=3273   Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  8. 【POJ 3273】 Monthly Expense (二分)

    [POJ 3273] Monthly Expense (二分) 一个农民有块地 他列了个计划表 每天要花多少钱管理 但他想用m个月来管理 就想把这个计划表切割成m个月来完毕 想知道每一个月最少花费多少 ...

  9. Divide and Conquer:Monthly Expense(POJ 3273)

    Monthly Expense 题目大意:不废话,最小化最大值 还是直接套模板,不过这次要注意,是最小化最大值,而不是最大化最小值,判断的时候要注意 联动3258 #include <iostr ...

随机推荐

  1. PAT甲1101 Quick Sort

    1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorit ...

  2. HDU 1083 - Courses - [匈牙利算法模板题]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...

  3. 学习计划 nginx 中 php的配置详解

    本章只看一个刚下载的nginx是如何支持php的 -- location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_inde ...

  4. sql 对某列取值进行if判断

    select  if(area_id =350000, 1, 2)  as area_id from my_table 取地区编号为350000的设置成 1, 其他的设置成2

  5. Closest Common Ancestors---poj1470(LCA+离线算法)

    题目链接:http://poj.org/problem?id=1470 题意是给出一颗树,q个查询,每个查询都是求出u和v的LCA:    以下是寻找LCA的预处理过程: void LCA(u){ f ...

  6. chown 命令

    root@localhost ~]# .txt # 同时修改文件属主和属组 !chown 执行上一个chown命令

  7. jmeter之Java request报错:java.lang.NoClassDefFoundError: redis/clients/jedis/Jedis

    今天在学习Jmeter的java request,请求内容是连接redis并获取其中的一个字段值.结果在运行时报如下错误: 2018/05/24 13:08:20 ERROR - jmeter.thr ...

  8. Inception系列

    从GoogLeNet的Inceptionv1开始,发展了众多inception,如inception v2.v3.v4与Inception-ResNet-V2. 故事还是要从inception v1开 ...

  9. Scala集合类详解

    对scala中的集合类虽然有使用,但是一直处于一知半解的状态.尤其是与java中各种集合类的混合使用,虽然用过很多次,但是一直也没有做比较深入的了解与分析.正好趁着最近项目的需要,加上稍微有点时间,特 ...

  10. INT_MAX和INT_MIN注意事项

    版权声明:转载请注明出处 http://blog.csdn.net/TwT520Ly https://blog.csdn.net/TwT520Ly/article/details/53038345 I ...