POJ 3273 Monthly Expense
Time Limit: 2000MS Memory Limit: 65536K
Description
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.
FJ wants to create a budget for a sequential set of exactly M (1 ≤ M ≤ N) fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.
FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.
Input
Lines 2..N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day
Output
Sample Input
7 5
100
400
300
100
500
101
400
Sample Output
500
Hint
Source
#include <cstdio>
using namespace std; const int N(1e5+);
int a[N];
int oo=1e9+;
int n, m;
bool C(int x){
int s=, c=;
for(int i=; i<n; i++)
s+a[i]>x ? s=a[i], c++ : s+=a[i];
return ++c<=m;
}
int main(){
scanf("%d%d", &n, &m);
for(int i=; i<n; i++)
scanf("%d", a+i);
int l=, r=oo, mid;
for(; r-l>; mid=(l+r)>>, C(mid)?r=mid:l=mid);
while(r-l!=);
printf("%d\n", r);
}
AC
#include <cstdio>
using namespace std; const int N(1e5+);
int a[N];
int oo=1e9+;
int n, m;
bool C(int x){
int s=, c=;
for(int i=; i<n; i++){
if(a[i]>x) return ;
s+a[i]>x ? s=a[i], c++ : s+=a[i];
}
return ++c<=m;
}
int main(){
scanf("%d%d", &n, &m);
for(int i=; i<n; i++)
scanf("%d", a+i);
int l=, r=oo, mid;
for(; r-l>; mid=(l+r)>>, C(mid)?r=mid:l=mid);
while(r-l!=);
printf("%d\n", r);
}
POJ 3273 Monthly Expense的更多相关文章
- POJ 3273 Monthly Expense(二分查找+边界条件)
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...
- 二分搜索 POJ 3273 Monthly Expense
题目传送门 /* 题意:分成m个集合,使最大的集合值(求和)最小 二分搜索:二分集合大小,判断能否有m个集合. */ #include <cstdio> #include <algo ...
- POJ 3273 Monthly Expense二分查找[最小化最大值问题]
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...
- [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14158 Accepted: 5697 ...
- POJ 3273 Monthly Expense(二分答案)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 36628 Accepted: 13620 Des ...
- poj 3273 Monthly Expense(贪心+二分)
题目:http://poj.org/problem?id=3273 题意:把n个数分成m份,使每份的和尽量小,输出最大的那一个的和. 思路:二分枚举最大的和,时间复杂度为O(nlog(sum-max) ...
- POJ 3273 Monthly Expense 二分枚举
题目:http://poj.org/problem?id=3273 二分枚举,据说是经典题,看了题解才做的,暂时还没有完全理解.. #include <stdio.h> #include ...
- poj 3273 Monthly Expense (二分搜索,最小化最大值)
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...
- POJ 3273 Monthly Expense(二分搜索)
Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...
随机推荐
- 转 异常处理汇总 ~ 修正果带着你的Net飞奔吧!
异常处理汇总 ~ 修正果带着你的Net飞奔吧! 异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983.html 异常处理汇总-开发工具 h ...
- 一篇文章告诉你为何GitHub估值能达20亿美元
软件开发平台GitHub今日宣布,已获得硅谷多家知名风投2.5亿美元融资,这也让其融资总额达到了3.5亿美元,此轮融资对GitHub的估值约为20亿美元. GitHub有何特别之处? GitHub创立 ...
- struts2验证框架
如何做一个工号 用户 密码 验证登录页面? 答:1,先画一个login.jsp ,如何画呢?先引入Struts2标签库,利用Struts2标签库画登录页面:如下: 2,先进入useractiion,在 ...
- 关于js中onclick字符串传参问题
规则: 外变是“”,里面就是‘’外边是‘’,里边就是“” 示例: var a="111"; var html="<a onclick='selecthoods( ...
- 【C#】【Thread】ManualResetEvent和AutoResetEvent区别
ManualResetEvent和AutoResetEvent主要用于线程之间同步问题. 主要使用方法有Set();Reset();WaitOne(); Set():将事件状态设置为终止状态,允许一个 ...
- C语言 三级指针的应用
//三级指针的使用 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #includ ...
- 从log4j日志无缝迁移至logback
ogback对比log4j的有点在此就不赘述了. 由于在项目的原有代码中,大量的日志生成是通过log4j实现的,新的代码希望通过logback的方式生成日志,同时希望将老的代码在不修改的情况下直接将日 ...
- Ajax实现异步操作实例_针对XML格式的请求数据
js分类中有一节[原生js异步请求,XML解析]主要说明了js前台是如何处理XML格式请求和如何接受由服务器返回的XML数据的解析,今天我将用一个实例来说明具体要如何操作. 前台的参数类型也是XML使 ...
- [MySQL] 按日期进行统计(前一天、本周、某一天)
在mysql数据库中,常常会遇到统计当天的内容.例如,在user表中,日期字段为:log_time统计当天 sql语句为: select * from user where date(log_time ...
- 如何在WPF中引用Windows.System.Forms.Integration
转自 http://www.cnblogs.com/sinozhang1988/archive/2012/11/28/2792804.html “未找到程序集 WindowsFormsIntegrat ...