直接二分答案然后判断.

-----------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ;  i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int maxn = int( 1e5 ) + 5;
  

int money[ maxn ];

 
int n , m;
 
bool jud( int x ) {
int cur = 0 , cnt = 0;
rep( i , m ) {
while( cur < n && cnt + money[ cur ] <= x ) 
   
   cnt += money[ cur++ ];
   
cnt = 0;
}
return cur < n ? 0 : 1;
}
 
int main() {
// freopen( "test.in" , "r" , stdin );
cin >> n >> m;
int L = 0 , R = 0;
rep( i , n ) {
   scanf( "%d" , money + i );
L = max( L , money[ i ] );
R += money[ i ];
}
int ans = 0;
while( L <= R ) {
int mid = ( L + R ) >> 1;
if( jud( mid ) ) 
   
   ans = mid , R = mid - 1;
   
else 
 
   L = mid + 1;
   
}
cout << ans << "\n";
   
return 0;
}

-----------------------------------------------------------------------------

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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 646  Solved: 319
[Submit][Status][Discuss]

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 月度开支

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

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

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

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

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

  4. 【BZOJ】1639: [Usaco2007 Mar]Monthly Expense 月度开支(二分)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1639 同tyvj1359,http://www.cnblogs.com/iwtwiioi/p/394 ...

  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. SMTP邮件传输协议发送邮件和附件

    在以前接触的项目中,一直都是在做网站时用到了发送mail 的功能,在asp 和.net 中都有相关的发送mail 的类, 实现起来非常简单.最近这段时间因工作需要在C++ 中使用发送mail 的功能, ...

  2. Spring-AOP实践

    Spring-AOP实践 公司的项目有的页面超级慢,20s以上,不知道用户会不会疯掉,于是老大说这个页面要性能优化.于是,首先就要搞清楚究竟是哪一步耗时太多. 我采用spring aop来统计各个阶段 ...

  3. 基于纯Java代码的Spring容器和Web容器零配置的思考和实现(3) - 使用配置

    经过<基于纯Java代码的Spring容器和Web容器零配置的思考和实现(1) - 数据源与事务管理>和<基于纯Java代码的Spring容器和Web容器零配置的思考和实现(2) - ...

  4. 【解决方法】You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)

    出现场景: 正常调试是没有问题的,但是在Archive的时候,报出了这个错误. 问题详情: (null): URGENT: all bitcode will be dropped because ‘x ...

  5. centos6.5设备mysql5.6

    1. 首先检查版本号number # uname -a 要么 # cat /etc/redhat-release CentOS release 6.6 (Final) 2. 下载并安装Mysql的yu ...

  6. linux多线程示例

    #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h& ...

  7. C++中++运算符的重载

    void showTime() const; Clock& operator ++(); Clock operator ++(int); private: int hour,minute,se ...

  8. POJ 3461 Oulipo(模式串在主串中出现的次数)

    题目链接:http://poj.org/problem?id=3461 题意:给你两个字符串word和text,求出word在text中出现的次数 思路:kmp算法的简单应用,遍历一遍text字符串即 ...

  9. SubLime2 乱码解决

    参考 http://www.fuzhaopeng.com/2012/sublime-text-2-with-gb2312-gbk-support/ 使用其中提到的方法二安装 首先下载http://su ...

  10. spring boot 下 500 404 错误页面处理

    spring boot 作为微服务的便捷框架,在错误页面处理上也有一些新的处理,不同于之前的spring mvc 500的页面处理是比较简单的,用java config或者xml的形式,定义如下的be ...