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 ...
随机推荐
- Apk大瘦身
Android的apk文件越来越大了这已经是一个不争的事实.在Android 还是最初版本的时候,一个app的apk文件大小也还只有2 MB左右,到了现在,一个app的apk文件大小已经升级到10MB ...
- WeChat on Web 部分功能模拟实现
Flask from flask import Flask,request,render_template,session,jsonify import time import requests im ...
- AndroidManifest.xml activity属性设置大全
1.android:allowTaskReparenting=["true"|"false"] 是否允许activity更换从属的任务,比如从短信息任务切换到浏 ...
- Android以root起一个process[shell脚本的方法]
有时候我们写的app要用uid=0的方式启动一个process,framework层和app层是做不到的,只有通过写脚本,利用am来实现.下面是具体步骤: 1.创建一个包含Main()方法Java p ...
- HAWQ取代传统数仓实践(十八)——层次维度
一.层次维度简介 大多数维度都具有一个或多个层次.例如,示例数据仓库中的日期维度就有一个四级层次:年.季度.月和日.这些级别用date_dim表里的列表示.日期维度是一个单路径层次,因为除了年-季度- ...
- JavaScript中的二分法插入算法
算法主体部分 var OnlineUser = { //list : 待查找的数组 //key : 待插入的值 //order : 数组的顺序 1:从小到大 0:从大到小 //start : 开始查找 ...
- everything 全盘文件查找工具及正则表达式的使用
首先需要开启 everything 工具在(字符串)查找时,对正则表达式功能的支持: [菜单栏]⇒ [Search]⇒ 勾选[Enable Regex] ctrl + i:字符大小写敏感/不敏感 1. ...
- sublime上配置markdown
等等等等 简书一个不错的教程:Sublime Text3的Markdown配置 补充说明:第一步可以直接找 Tools-->install package control. ^.^ ...
- SHELL 脚本----常用的命令
一个很不错的bash脚本编写教程,至少没接触过BASH的也能看懂 建立一个脚本 Linux中有好多中不同的shell,但是通常我们使用bash (bourne again shell) 进行she ...
- vector释放内存之swap方法
相信大家看到swap这个词都一定不会感到陌生,就是简单的元素交换.但swap在C++ STL中散发着无穷的魅力.下面将详细的说明泛型算法swap和容器中的swap成员函数的使用! 1. 泛型算法swa ...