http://www.lydsy.com/JudgeOnline/problem.php?id=1639

同tyvj1359,http://www.cnblogs.com/iwtwiioi/p/3942145.html

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=100005;
int n, m, a[N]; inline const bool check(const int &x) {
int sum=0, t=0, i;
for(i=1; i<=n; ++i) {
sum+=a[i];
if(sum>x) sum=a[i], ++t;
if(t>=m) return 0;
}
return 1;
} int main() {
read(n); read(m);
int mx=0, sum=0;
for1(i, 1, n) { read(a[i]); mx=max(mx, a[i]); sum+=a[i]; }
int l=mx, r=sum, mid;
while(l<=r) {
mid=(l+r)>>1;
if(check(mid)) r=mid-1;
else l=mid+1;
}
print(r+1);
return 0;
}

Description

Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的。他已经计算了他以后 N(1<=N<=100,000)个工作日中每一天的花费moneyi(1<=moneyi<=10,000),他想要为他连续 的M(1<=M<=N)个被叫做“清算月”的结帐时期做一个预算,每一个“清算月”包含一个工作日或更多连续的工作日,每一个工作日都仅被包 含在一个“清算月”当中。 FJ的目标是安排这些“清算月”,使得每个清算月的花费中最大的那个花费达到最小,从而来决定他的月度支出限制。

Input

第一行:两个用空格隔开的整数:N和M

第2..N+1行:第i+1行包含FJ在他的第i个工作日的花费

Output

第一行:能够维持每个月农场正常运转的钱数

Sample Input

7 5
100
400
300
100
500
101
400

Sample Output

500
输入细节

这里有7个工作日来被5个“清算月”划分。他花费100,400,100,500,101,和400元在他的每个工作日。

输出细节

如果FJ安排他的月度预算,他将把前两天划分在一个月中,把第三天、第四天划分在一个月当中,最后的三个工作日各自在一个月当中,所以他一个月最多花费500元,其他的方法总是得出一个较大的结果。

100 400 300 100 500 101 400 每天花费
---1--- ---2--- -3- -4- -5- 月度标号
500 400 500 101 400 月度花费

HINT

Source

【BZOJ】1639: [Usaco2007 Mar]Monthly Expense 月度开支(二分)的更多相关文章

  1. BZOJ 1639: [Usaco2007 Mar]Monthly Expense 月度开支( 二分答案 )

    直接二分答案然后判断. ----------------------------------------------------------------------------- #include&l ...

  2. BZOJ 1639: [Usaco2007 Mar]Monthly Expense 月度开支

    Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N<=100 ...

  3. bzoj 1639: [Usaco2007 Mar]Monthly Expense 月度开支【二分】

    忘开long long了居然没WA 二分答案,枚举判断看最后需要的月份数是否小于等于要求的即可 #include<iostream> #include<cstdio> usin ...

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

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

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

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

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

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

  7. 【二分答案】bzoj1639 [Usaco2007 Mar]Monthly Expense 月度开支

    #include<cstdio> using namespace std; #define N 100001 int n,m,a[N]; bool check(int x) { int n ...

  8. bzoj 1637: [Usaco2007 Mar]Balanced Lineup

    1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John ...

  9. Bzoj 1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 传递闭包,bitset

    1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 323  Solved ...

随机推荐

  1. GameCenter 使用指南

    原地址:http://www.cocoachina.com/gamedev/misc/2010/1022/2229.html GameCenter 为单机游戏为主的 iPhone 游戏平台引入了社会化 ...

  2. mac中使用vi修改二进制文件

    mac中使用vi修改二进制文件 1.首先以二进制方式编辑这个文件vi -b datafile 2.使用xxd转换为16进制:%!xxd 文本看起来像这样: 0000000: 1f8b 0808 39d ...

  3. potplayer 网页调用potplayer播放本地视频

      网页调用potplayer播放本地视频 CreateTime--2018年1月3日10:36:24 Author:Marydon 源码展示: <!DOCTYPE html> <h ...

  4. STRUTS2配置动态页面

      STRUTS2配置动态页面 CreateTime--2017年5月11日09:00:31Author:Marydon 1.struts配置 <?xml version="1.0&q ...

  5. 记一次CurrentDirectory导致的问题

    现在项目里需要实现一个功能如下: A.exe把B.exe复制到临时目录,然后A.exe退出,B.exe负责把A.exe所在的整个目录删除. 实现: A.exe用CreateProcess创建B.exe ...

  6. ADBport被占用,adb server is out of date

    wd=adb&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YdPWD1uyP-PHf1ryRYP1Nh0ZwV5Hcvrj ...

  7. DP SRM 661 Div2 Hard: ColorfulLineGraphsDiv2

    Problem Statement Bob is going to create a graph with N nodes. The graph will be constructed in two ...

  8. 【Redis】redis+php处理高并发,很好的教程||附上 php的文件锁

    链接至:http://blog.csdn.net/nuli888/article/details/51865401 很好的教程,其中redis+php有点小问题. 附上php文件锁: $fp = fo ...

  9. C#:依据目录填充树视图

    #region 依据目录填充树视图 /// <summary> /// 依据文件夹目录,填充树视图 /// </summary> /// <param name=&quo ...

  10. pip install mysql-connector 安装出错

    一.MySQL Connector/Python 2.2.3 的变化: 之前 mysql 官方说MySQL Connector/Python 是纯python语言写的,但是呢! 这个问题在2.2.3中 ...