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. Google Drive 里的文件下载的方法

    Google Drive 里并不提供创建直接下载链接的选项,但是可以通过小小的更改链接形式就能把分享的内容保存到本地.例如,一份通过 Google Drive 分享的文件链接形式为: https:// ...

  2. Linux--抓取Appium网站命令

    # 获取各命令url地址 curl http://appium.io/docs/en/commands/device/app/is-app-installed/ 2>/dev/null | gr ...

  3. svn冲突的解决

    svn文件冲突的解决 冲突后,会产生三个多余的文件. ①文件名.扩展名.mine 这是你的文件,在你更新你的工作副本之前存在于你的工作副本中--也就是说,没有冲突标志.这个文件 除了你的最新修改外没有 ...

  4. Python高阶函数(Map、Reduce、Filter)

    Map函数 map()函数接收两个参数,一个是函数,一个是序列,map将传入的函数依次作用到序列的每个元素,并把结果作为新的list返回. 举例说明 比如我们有一个函数f(x)=x2,要把这个函数作用 ...

  5. 【剑指offer】矩形覆盖

    一.题目: 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 二.思路: 斐波那契数列 三.代码:     

  6. rplidar跑cartographer

    一.Cartographer编译 cartographer依赖的大型第三方库很少,编译时基本没有依赖项问题,基本按照官方文档的步骤来,略作修改.使用的环境是Ubuntu16.04+ROS Kineti ...

  7. 不需要更多JS框架了

    现在,JavaScript框架已成为Web项目开发不可或缺的一部分.那是因为很长一段时间以来,各种浏览器之间有很大的差别,人们不得不编写框架对此进行屏蔽.问题在于,各种浏览器甚至在基本问题上都难以取得 ...

  8. [py模块]random&string取随机字符串

    栗子 - 取n位的随机字符串(大小写/数字) def get_random_str(len_str): import string import random letters_nums = strin ...

  9. 如何快速获取ListView的打气筒对象

    简单的方式有三种: @Override public View getView(int position, View convertView, ViewGroup parent) { View vie ...

  10. C#webBrowser使用代理服务器的方法winform

    其实在C#中使用webBrowser大家应该都会了,论坛也有很多相前的例子大家可以查询一下就知道了但是像直接使用浏览器一样设置代理 的方法可能很多人还不知道吧.这个其实是调用一个Dll文件进行设置的, ...