POJ3273(最大化问题)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 20603 | Accepted: 8101 |
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
题意:将N个数分成M组,使每组之和的最大值最小。
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=;
int n,m;
int spe[MAXN];
bool test(int mon)
{
int s=;
int sum=;
for(int i=;i<n;i++)
{
if(spe[i]>mon) return false;
if(sum+spe[i]<=mon)
{
sum+=spe[i];
}
else
{
sum=spe[i];
s++;
}
}
s++;
return s<=m;
}
int main()
{
while(cin>>n>>m)
{
for(int i=;i<n;i++)
{
cin>>spe[i];
}
int l=;
int r=0x3f3f3f3f;
while(r-l>)
{
int mid=(l+r)>>;
if(test(mid)) r=mid;
else l=mid;
}
cout<<r<<endl;
}
return ;
}
POJ3273(最大化问题)的更多相关文章
- ubuntu终端窗口最大化(不是全屏)
窗口最大化:ctrl+win窗+↑ 窗口还原:ctrl+win窗+↓ 这快捷键让人无语.好好的gnome被改造成unity,快捷键也改掉了.win窗+↑/↓为啥不用呢? 还有就是terminal的ta ...
- Winform窗体最大化的时候,如何指定窗体的位置、大小
一.重写窗体的SizeChanged事件不能改变窗体最大化的位置和大小. public partial class Form2 : Form { public Form2() { Initialize ...
- Easyui 让Window弹出居中与最大化后居中
easyui1.3.2版本,window的弹出不会居中了.而dialog是会居中的,我们必须为为window的open事件做扩展 代码如下:只要加入以下代码即可.如果你是看了MVC项目系列的,把他放到 ...
- 【荐2】Total Commander 7.57 配置选项 个性化设置备份,,,开启时如何自动最大化???(二)
最近安装了下新版的“Total Commander 7.56”,发现它的默认设置是如此的不好用,现把对其个性化设置备份如下(符合大部分用户的操作习惯): 默认打开Total Commander 7.5 ...
- C# WinForm 禁止最大化、最小化、双击标题栏、双击图标等操作(转载)
protected override void WndProc(ref Message m) { if (m.Msg==0x112) { switch ((int) m.WParam) { //禁止双 ...
- VC++ 如何使窗体最大化或是最小化
最大化最小的使得的函数是 ShowWindow函数 ShowWindow(SW_SHOWMINIMIZED);//最小化 ShowWindow(SW_SHOWMAXIMIZED);//最大化 Show ...
- ACM Yougth的最大化
Yougth的最大化 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价 ...
- winform窗体最大化、最小化、还原
//最大化 private void button_maxsize_Click(object sender, EventArgs e) { this.WindowS ...
- wpf 自定义窗口,最大化时不覆盖任务栏
相信很多人使用wpf时会选择自定义美观的窗口,因此会设置WindowStyle="None" 取消自带的标题栏.但这样使用 WindowState="Maximized& ...
随机推荐
- C 标准库 - <limits.h>
C 标准库 - <limits.h> 简介 limits.h 头文件决定了各种变量类型的各种属性.定义在该头文件中的宏限制了各种变量类型(比如 char.int 和 long)的值. 这些 ...
- poj 1651 Multiplication Puzzle【区间DP】
题目链接:http://poj.org/problem? id=1651 题意:初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n) 同一时候ans+=a ...
- Java数据库访问技术
1.Java集合: Collection Map List: 位于 java.util包中. Arraylist 顺序结构.Linkedlist 链表结构 // List<NewsClassif ...
- Ubuntu下安装libsvm
在安装LibSVM前需要先装 python 和 gnuplot linux 一般都自带了python2.7,所以python的安装不再赘述 在 ubuntu 下安装 gnuplot 不能直接 sudo ...
- c和c++的输入输出
格式输出: printf(格式控制, 输出表列); %d 十进制数 %md m为指定的宽度 若数据位数小于m,则左端补以空格;若大于m,则按实际位数输出 %ld 长整型数据 %mld 指定字段宽 ...
- PythonCookBook笔记——数据结构和算法
数据结构和算法 解包赋值 p = [1, 2, 3] a, b, c = p # _表示被丢弃的值 _, d, _ = p # 可变长解包 *a, b = p # 字串切割解包 line = 'nob ...
- wince c# 创建桌面快捷方式 .
static void Create() { string PathGPRS = System.IO.Path.GetDirectoryName(System.Reflection.Assembly. ...
- mongoose在Windows Server 2003上不能访问问题的解决
这两天在部署EasyDarwin开源流媒体服务器到Windows Server 2003的时候,奇怪地发现,在Windows 2003上面,mongoose的web管理端口居然无法访问,但通过nets ...
- Dubbo Spring Cloud Motan
跨语言统一治理.Golang,谈谈另辟蹊径的开源RPC框架Motan_搜狐科技_搜狐网 https://www.sohu.com/a/207389967_467759
- Linux就该这么学--命令集合7(管道命令符)
1.管道命令符“|”的作用是将前一个命令的标准输出当作后一个命令的标准输入,格式为:“命令A|命令B”. 找出被限制登录用户的命令是:grep "/sbin/nologin" /e ...