POJ3273:Monthly Expense(二分)
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
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int a[100005];
int main()
{
int n,m;
int sum,maxn,i,j,s,cnt,mid;
while(~scanf("%d%d",&n,&m))
{
sum = 0,maxn = 0;
for(i = 0; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
maxn = max(maxn,a[i]);
}
while(maxn<sum)
{
mid = (sum+maxn)>>1;
s = 0,cnt = 0;
for(i = 0; i<n; i++)
{
s+=a[i];
if(s>mid)
{
s = a[i];
cnt++;
}
}
if(cnt<m) sum = mid;
else maxn = mid+1;
}
printf("%d\n",maxn);
} return 0;
}
POJ3273:Monthly Expense(二分)的更多相关文章
- POJ3273 Monthly Expense —— 二分
题目链接:http://poj.org/problem?id=3273 Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 【POJ 3273】 Monthly Expense (二分)
[POJ 3273] Monthly Expense (二分) 一个农民有块地 他列了个计划表 每天要花多少钱管理 但他想用m个月来管理 就想把这个计划表切割成m个月来完毕 想知道每一个月最少花费多少 ...
- POJ 3273 Monthly Expense二分查找[最小化最大值问题]
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...
- Monthly Expense(二分查找)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17982 Accepted: 7190 Desc ...
- POJ 3273 Monthly Expense(二分查找+边界条件)
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...
- POJ 3273 Monthly Expense(二分答案)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 36628 Accepted: 13620 Des ...
- POJ3273 Monthly Expense 2017-05-11 18:02 30人阅读 评论(0) 收藏
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25959 Accepted: 10021 ...
- POJ-3273 Monthly Expense (最大值最小化问题)
/* Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10757 Accepted: 4390 D ...
- POJ 3273:Monthly Expense 二分好题啊啊啊啊啊啊
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19207 Accepted: 7630 ...
随机推荐
- c#使用Microsoft Excel 12.0 object Libary导出的Excel文件office2003不能打开!!~~(分享)
-----转载:http://hi.baidu.com/zhang_zhu_1/item/f3d47d1f86bf037a70d5e87e 使用C#导出数据到Excel文件时,Excel 2007组件 ...
- 状态开关按钮(ToggleButton)及按钮(Swich)的使用
状态开关按钮(ToggleButton)和开关(Switch)也是由Button派生出来的,因此它们本质上都是按钮,Button支持的各种属性.方法也适用于ToggleButton和Switch.从功 ...
- MySQL 管理
MySQL 管理 启动及关闭 MySQL 服务器 首先,我们需要通过以下命令来检查MySQL服务器是否启动: ps -ef | grep mysqld 如果MySql已经启动,以上命令将输出mysql ...
- java_annotation_01
一,Annotation简介 J2SE5.0提供了很多新的我,其中一个很重要的我就是对元数据的支持,在J2SE5.0中,这种元数据被称为注释,通过使用注释,程序开发人员可以在不改变原有逻辑的情况下,在 ...
- jQuery操作cookie
验证jquery的cookie插件时才知道原先文件一直在桌面上放着执行发现没有效果,文件必须放在web服务器下面执行才会生效,晕菜! $.cookie(name,value,{expires: 7,p ...
- Bug: freetype/fterrors.h: No such file or directory
Bug描述: 安装PIL过程中出现题目中的错误信息,具体如下:
- 获取上海地区AQI质量数据Python脚本
一个获取上海地区AQI质量的Python脚本 https://github.com/yanyueoo7/Raspberrypi/blob/master/GetPmData_Shanghai.py #! ...
- linux和windows下,C/C++的sleep函数
简介: 函数名: sleep 功 能: 执行挂起一段时间 用 法: unsigned sleep(unsigned seconds); 在VC中使用带上头文件 #include < ...
- POJ2513 Colored Sticks(欧拉)
题目链接. 题目大意: 给很多木棍,两端被涂了颜色.任意两根木棍的相同颜色处可以拼接在一起,问有没有可能将所有的木棍都连起来,成一条直线? 分析: 考点,欧拉道路. 将一根木棍看成一条边,两端的颜色看 ...
- 【转】Android中的内存管理--不错不错,避免使用枚举类型
原文网址:http://android-performance.com/android/2014/02/17/android-manage-memory.html 本文内容翻译自:http://dev ...