Monthly Expense(二分--最小化最大值)
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 <iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=1e5+;
const int Inf=0x3f3f3f3f;
int m,n;
int str[MAXN];
int solve(int mid)
{
int sum=,cnt=;
for(int i=;i<m;i++)
{
if(sum+str[i]<=mid)
{
sum+=str[i];
}
else
{
sum=str[i];
cnt++;
}
}
if(cnt>n)
return ;
return ;
}
int main()
{
while(scanf("%d%d",&m,&n)!=-)
{ int left=,right=,mid;
for(int i=;i<m;i++)
{
scanf("%d",&str[i]);
right+=str[i];
left=max(left,str[i]);
}
while(left<=right)
{
mid=(right+left)/;
if(solve(mid))
{
right=mid-;
}
else
{
left=mid+;
}
}
printf("%d\n",mid);}
return ;
}
Monthly Expense(二分--最小化最大值)的更多相关文章
- OJ 21658::Monthly Expense(二分搜索+最小化最大值)
Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N< ...
- poj 3273"Monthly Expense"(二分搜索+最小化最大值)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 天,第 i 天会有 a[ i ] 的花费: 将这 N 天分成 M 份,每 ...
- POJ_3273_Monthly_Expense_(二分,最小化最大值)
描述 http://poj.org/problem?id=3273 共n个月,给出每个月的开销.将n个月划分成m个时间段,求m个时间段中开销最大的时间段的最小开销值. Monthly Expense ...
- POJ_3104_Drying_(二分,最小化最大值)
描述 http://poj.org/problem?id=3104 n件衣服,第i件衣服里面有水a[i],自然风干每分钟干1个水,用吹风机每分钟干k个水,但是同时只能对一件衣服使用吹风机,求干完所有衣 ...
- POJ 3273 Monthly Expense二分查找[最小化最大值问题]
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...
- poj 3273 Monthly Expense (二分搜索,最小化最大值)
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...
- POJ3273-Monthly Expense (最小化最大值)
题目链接:cid=80117#problem/E">click here~~ [题目大意] 农夫JF在n天中每天的花费,要求把这n天分作m组.每组的天数必定是连续的.要求分得各组的花费 ...
- 【POJ 3273】 Monthly Expense (二分)
[POJ 3273] Monthly Expense (二分) 一个农民有块地 他列了个计划表 每天要花多少钱管理 但他想用m个月来管理 就想把这个计划表切割成m个月来完毕 想知道每一个月最少花费多少 ...
- [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14158 Accepted: 5697 ...
随机推荐
- Python基础学习(第6天)
1.zip函数 1)zip函数在只有一个参数时运作的方式. x = [1, 2, 3] x = zip(x) print x输出:[(1,), (2,), (3,)] 2)zip函数在没有参数时运作的 ...
- CallKit iOS 教程
原文:CallKit Tutorial for iOS 作者:József Vesza 译者:kmyhy 对 VoIP App 开发者来说,iOS 的支持并不友好.尤其是它的通知发送这一块,太糙了.你 ...
- 在ubuntu16.04上安装php7 mysql5.7 nginx1.10并支持http2
安装nginx 首先更新软件包 并且安装nginx sudo apt-get update sudo apt-get install nginx 开放防火墙配置 sudo ufw allow 'Ngi ...
- MyEclipse2014快速配置Spring & Spring Testing, Spring AOP简单使用
1.新建项目 2.右击项目,如图,利用myeclipse自动导入spring 3.在弹出的对话框中一直next到最后,在最后的页面中勾选Spring Testing,完成. 4.在src下的appli ...
- Mac OS X显示隐藏文件命令
defaults write com.apple.finder AppleShowAllFiles Yes && killall Finder //显示隐藏文件 defaults wr ...
- jfrog artifactory jenkins pipeline 集成
1. 预备环境 artifactory ( 开源版本 ) maven jenkins jenkins artifactory plugin (在插件管理安装即可) 2. 配置artifactory ...
- fn project 运行时配置选项
Env Variables Description Default values DB_URL The database URL to use in URL format. SeeDatabases ...
- RESTful Get方式传参json格式后端400 解决方案
前端采用vue+axios 后端采用spring boot restful 问题: 前端get 请求需要传递array 字段值 后端由于tomcat 版本问题,不支持url接受特殊字符包括 [] {} ...
- FastAdmin 在线命令生成时出错的分析
FastAdmin 在线命令生成时出错的分析 出错现象 版本环境 FastAdmin 版本:1.0.0.20180806_beta 在线命令插件版本:1.0.3 分析 2018-08-13 16:12 ...
- Java 多个引用类型变量引用同一个对象
引用类型变量在声明后必须引用对象才能使用. 一个引用变量只能唯一指向一个对象,但同一个对象可被多个引用类型变量引用. 如:MyDate today; //将变量跟配给一个保存引用的空间(栈) toda ...