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. windows下安装pytorch

    安装: https://blog.csdn.net/xiangxianghehe/article/details/80103095 Windows下通过pip安装PyTorch 0.4.0 impor ...

  2. Oracle安装部署之RedHat安装Oracle11g_R2

    硬件配置 内存 :≥1G 硬盘空间:≥10G 上传oracle11g安装包: putty上用wcw用户登录,通过ftp服务上传oracle安装文件到/home/wcw目录下解压 #unzip linu ...

  3. Python:闭包

    闭包(Closure) 在一个函数内部定义另一个函数,然后内部函数用到外部函数的变量,把内部函数以及用到的外部变量,合称闭包. 首先复习一下 命名空间与作用域 我们可以把命名空间看做一个大型的字典类型 ...

  4. 数据结构——栈(C语言实现)

    #include <stdio.h> #include <stdlib.h> #include<string.h> #include<malloc.h> ...

  5. iOS-绘图之CoreGraphics框架

    第一步:先科普一下基础知识: Core Graphics是基于C的API,可以用于一切绘图操作 Core Graphics 和Quartz 2D的区别 quartz是一个通用的术语,用于描述在iOS和 ...

  6. gateio API

    本文介绍gate io API 所有交易对 API 返回所有系统支持的交易对 URL: https://data.gateio.io/api2/1/pairs 示例: # Request GET: h ...

  7. 2018/03/11 每日一个Linux命令 之 top

    每日一个Linux命令 之 top   今天在公司测试服务器上跑了一个我写的功能[本地测试过的],但是不知道怎么跑了个无限死循环出来,一个文件的体积在不停的变大,如果不管的话这能行? 上去一看,PHP ...

  8. function $(id) {}表示什么函数

    function $(id) {}表示什么函数 一.总结 1.就是简写,不然每次打document.getElementById很烦 二.问题 function $(id) {return docum ...

  9. Kafka介绍及安装部署

    本节内容: 消息中间件 消息中间件特点 消息中间件的传递模型 Kafka介绍 安装部署Kafka集群 安装Yahoo kafka manager kafka-manager添加kafka cluste ...

  10. 【剑指offer】从上往下打印二叉树

    一.题目: 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 二.思路: 用队列,用根节点初始化队列,然后依次从队列中取出节点,先把当前节点输出,并把左右子树分别放入队列,直到队列为空.欧了. ...