直接二分答案然后判断.

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

#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. Linux 用户信息,组信息,密码信息!

    1: 用户信息保存在  /etc/passwd 文件下 2: 密码信息保存在 /etc/shadow 3: 组相关的信息 /etc/group

  2. java中三种常见内存溢出错误的处理方法

    更多 10   相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题,这个问题曾困扰了我很长时间,随着解决各类问题经验的积累以及对问题根源的探索,终于有了一个比较深入的 ...

  3. Oracle数据库时间修改

    http://blog.csdn.net/tianlesoftware/article/details/6163859

  4. jquery submit()不能提交表单的解决方法

    <form id="form" method="get"> <input type="text" name="q ...

  5. openStack openSource CloudComputing

    <一,> ,OpenStack a few Core Compontents integration with openStack-keystone Identity service1.1 ...

  6. How to get the xpath by clicking an html element

    How to get the xpath by clicking an html element How to get the xpath by clicking an html element

  7. 字符串的MD5的32位加密和16位加密

    import java.security.MessageDigest; import java.util.Locale; public class MD5Util { public static St ...

  8. Windows环境下用C#编程将文件上传至阿里云OSS笔记

    Windows环境下用C#编程将文件上传至阿里云OSS笔记 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/ex_net/article/detai ...

  9. 记userscripts.org

    发现一些Firefox用户脚本不起作用,userscripts.org访问不能有一个很长的一段时间,我还以为出了什么问题没出去检查.前几天有时间检查脚本,在路上,然后返回到userscripts.or ...

  10. 深入理解 IE haslayout

    转载自Bubblings Blog 原文地址:http://riny.net/2013/haslayout/ 1.什么是haslayout layout是windows IE的一个私有概念,它决定了元 ...