题目链接

cid=80117#problem/E">click here~~

【题目大意】

农夫JF在n天中每天的花费,要求把这n天分作m组。每组的天数必定是连续的。要求分得各组的花费之和应该尽可能地小,最后输出各组花费之和中的最大值

【解题思路】:

经典的最小化最大值问题,要求连续的m个子序列,子序列的和最大值的最小,枚举满足条件的m的最小值即为答案。因此二分查找。

1.能否把序列划分为每一个序列之和不大于mid的m个子序列,

2.通过用当前的mid值能把天数分成几组,

3.比較mid和t的大小,从而确定mid

详细见代码吧:

//#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+10;
int n,m,num[N];
bool is_part(int mid)
{
int t=0,s=0; //t==当前mid值能把n天分成的组数(初始把所有天数作为0组)
bool ok=true;
for(int i=0; i<n; i++)//遍历每一天的花费
{
if(num[i]>mid){//假设某个值大于,显然不符合
ok=false;
break;
}
if(s+num[i]>mid){//不能再把当前元素加上了
t++;
s=num[i]; //把前i天作为一组
if(t>m-1){ //t=m时退出。即在最后一个元素之前都已经用了m条划分线
ok=false;
break;
}
}
else s+=num[i];//把当前元素与前面的元素加上。以便尽量往右划分,贪心究竟
}
return ok;
}
void judge() //二分查找
{
int ll=0,rr=1e8;
while(ll<rr)
{
int mid=(ll+rr)>>1;
if(is_part(mid)) rr=mid;
else ll=mid+1;
}
printf("%d\n",ll);
}
int main()
{
int maxx=0,sum=0;
scanf("%d%d",&n,&m);
for(int i=0; i<n; i++){
scanf("%d",&num[i]);
sum+=num[i];
maxx=max(maxx,num[i]);
}
if(m==n||m==1) printf("%d\n",maxx);
else judge();
return 0;
}

POJ3273-Monthly Expense (最小化最大值)的更多相关文章

  1. POJ-3273 Monthly Expense---最小化最大值

    题目链接: https://cn.vjudge.net/problem/POJ-3273 题目大意: 给N个数,划分为M个块(不得打乱数顺序).找到一个最好的划分方式,使得块的和的最大值 最小 解题思 ...

  2. POJ 3273 Monthly Expense二分查找[最小化最大值问题]

    POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...

  3. Monthly Expense(二分--最小化最大值)

    Farmer John is an astounding accounting wizard and has realized he might run out of money to run the ...

  4. poj 3273 Monthly Expense (二分搜索,最小化最大值)

    题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...

  5. OJ 21658::Monthly Expense(二分搜索+最小化最大值)

        Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N< ...

  6. POJ_3273_Monthly_Expense_(二分,最小化最大值)

    描述 http://poj.org/problem?id=3273 共n个月,给出每个月的开销.将n个月划分成m个时间段,求m个时间段中开销最大的时间段的最小开销值. Monthly Expense ...

  7. POJ_3104_Drying_(二分,最小化最大值)

    描述 http://poj.org/problem?id=3104 n件衣服,第i件衣服里面有水a[i],自然风干每分钟干1个水,用吹风机每分钟干k个水,但是同时只能对一件衣服使用吹风机,求干完所有衣 ...

  8. POJ-3273 Monthly Expense (最大值最小化问题)

    /* Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10757 Accepted: 4390 D ...

  9. [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)

    Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14158   Accepted: 5697 ...

随机推荐

  1. C#.Net 如何动态加载与卸载程序集(.dll或者.exe)6-----在不卸载程序域的前提下替换程序集文件。

    当某个程序集文件被载入AppDomain,该文件在AppDomain.Unload之前是不能被替换和删除的.使用AppDomainSetup的影像复制功能可以实现在不卸载程序的情况下替换或者删除程序集 ...

  2. 如何完全卸载VS2010

    1.首先用360卸载,当卸载完成后,提示有残余的话,就强力清除 2,接着,下载IobitUninstaller工具 3.按照下面进行卸载 1.Microsoft .NET Framework 4 框架 ...

  3. fiddler代理

    对于前段开发人员,fiddler 是一个必不可少的调试神器.下载地址:http://www.telerik.com/download/fiddler. 有同学也许会碰到,chrome 下 fiddle ...

  4. The Impact of Garbage Collection on Application Performance

    As we’ve seen, the performance of the garbage collector is not determined by the number of dead obje ...

  5. MySQL优化器 limit影响的case

    测试的用例中,因为limit的大小不同,而产生了完全不同的执行计划: 1. 测试case: create table t1 ( f1 ) not null, f2 ) not null, f3 ) n ...

  6. android源码GIT下载

    mkdir device cd device git clone https://android.googlesource.com/device/common.git mkdir htc cd htc ...

  7. [swustoj 1095] 挖金子

    挖金子(1095) 题目描述 你在一个N*M的区域中,一开始在(1,1)的位置,每个位置有可能有金子,也有可能不能到达,也有可能有传送门.你只能往右或者下走,不能走出这个区域.当你位于传送门时,传送门 ...

  8. JDK1.5新特性(七)……Annotations

    概述 Annotations (Metadata) - This language feature lets you avoid writing boilerplate code under many ...

  9. NOIP2006 能量项链

    洛谷1063 能量项链 本题地址:http://www.luogu.org/problem/show?pid=1063 题目描述 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N ...

  10. HW5.33

    import java.util.Calendar; public class Solution { public static void main(String[] args) { long tot ...