博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3273 Monthly Expense【二分】
阅读量:6821 次
发布时间:2019-06-26

本文共 1756 字,大约阅读时间需要 5 分钟。

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 ≤ MN) 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

Line 1: Two space-separated integers:
N and
M
Lines 2..
N+1: Line
i+1 contains the number of dollars Farmer John spends on the
ith day

Output

Line 1: The smallest possible monthly limit Farmer John can afford to live with.

Sample Input

7 5100400300100500101400

Sample Output

500 题目大意:给出农夫在n天中每天的花费,要求把这n天分作m组,每组的天数必然是连续的,要求分得各组的花费之和应该尽可能地小,最后输出各组花费之和中的最大值 思路:二分,标志性的字眼“最小中的最大值”, “最大之中的最小值”. 很好的解题报告: 代码如下:
View Code
#include
#include
#include
using namespace std;int n, m, f[100005];int judge(int mm){ int i, count=0, change=0; for(i=0; i
mm) { count++; change=f[i]; } } count++; if(count>m) return 1; return 0;}int main(){ while(scanf("%d%d", &n, &m)!=EOF) { int i, sum=0, maxmon=0; memset(f, 0, sizeof(f)); for(i=0; i
f[i]?maxmon:f[i]; } int left=maxmon, right=sum; while(left

 

 

转载于:https://www.cnblogs.com/Hilda/archive/2012/08/13/2635869.html

你可能感兴趣的文章
学习日志---linux磁盘矩阵RAID
查看>>
要不要fast-cgi
查看>>
js 获取当前年月日时分秒星期
查看>>
windows日志 编号10 wmi 错误处理
查看>>
win7安装laravel
查看>>
我的友情链接
查看>>
rpm 无响应
查看>>
Oracle 各后台进程功能说明
查看>>
屏蔽storm ui的kill功能
查看>>
我的友情链接
查看>>
Oracle Decode函数的使用
查看>>
MSF学习笔记
查看>>
经典脚本案例--check memory
查看>>
20.31 expect脚本同步文件;20.32 expect脚本指定host和要同步的文件;20.33 构建文件分发系统;20.34...
查看>>
CentOS单用户与救援模式
查看>>
华为交换机配置手工负载分担模式链路聚合LACP示例
查看>>
Django QuerySet API
查看>>
win 7 升级为IE11后打开IE后无反应解决办法
查看>>
rest 特征和优点
查看>>
postfix 源码centos7上搭建及错误提示---亲测
查看>>