洛谷—— P2884 [USACO07MAR]每月的费用Monthly Expense
https://www.luogu.org/problemnew/show/P2884
题目描述
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.
给出农夫在n天中每天的花费,要求把这n天分作m组,每组的天数必然是连续的,要求分得各组的花费之和应该尽可能地小,最后输出各组花费之和中的最大值
输入输出格式
输入格式:
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
输出格式:
Line 1: The smallest possible monthly limit Farmer John can afford to live with.
输入输出样例
说明
If Farmer John schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he spends at most $500 in any month. Any other method of scheduling gives a larger minimum monthly limit.
二分一个最大连续钱数,每次增加一个月份的钱,判断一次。注意统计最后的一组
#include <cstdio> inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
} const int N(1e5+); int n,m,w[N]; int L,R,Mid,ans;
inline bool check(int x)
{
int cnt=,now=w[];
for(int i=; i<=n; ++i)
{
if(now>x) return ;
if(now+w[i]>x)
{
cnt++;
now=w[i];
}
else now+=w[i];
}
if(now&&now<=x) cnt++;
return cnt<=m;
} int Presist()
{
read(n),read(m);
for(int i=; i<=n; ++i)
read(w[i]),R+=w[i];
for(; L<=R; )
{
Mid=L+R>>;
if(check(Mid))
{
ans=Mid;
R=Mid-;
}
else L=Mid+;
}
printf("%d\n",ans);
return ;
} int Aptal=Presist();
int main(int argc,char**argv){;}
洛谷—— P2884 [USACO07MAR]每月的费用Monthly Expense的更多相关文章
- bzoj1639 / P2884 [USACO07MAR]每月的费用Monthly Expense
P2884 [USACO07MAR]每月的费用Monthly Expense 二分经典题 二分每个段的限制花费,顺便统计下最大段 注意可以分空段 #include<iostream> #i ...
- P2884 [USACO07MAR]每月的费用Monthly Expense
题目描述 Farmer John is an astounding accounting wizard and has realized he might run out of money to ru ...
- [USACO07MAR]每月的费用Monthly Expense
题目:POJ3273.洛谷P2884. 题目大意:有n个数,要分成m份,每份的和要尽可能小,求这个情况下和最大的一份的和. 解题思路:二分答案,对每个答案进行贪心判断,如果最后得出份数>m,则说 ...
- 洛谷 1004 dp或最大费用流
思路: dp方法: 设dp[i][j][k][l]为两条没有交叉的路径分别走到(i,j)和(k,l)处最大价值. 则转移方程为 dp[i][j][k][l]=max(dp[i-1][j][k-1][l ...
- 洛谷P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…
P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many simi ...
- 洛谷P4003 无限之环(费用流)
传送门 神仙题啊……不看题解我可能一年都不一定做得出来……FlashHu大佬太强啦 到底是得有怎样的脑回路才能一眼看去就是费用流啊…… 建好图之后套个板子就好了,那么我们着重来讨论一下怎么建图 首先, ...
- 洛谷P2770 航空路线问题(费用流)
题意 $n$个点从左向右依次排列,有$m$条双向道路 问从起点到终点,再从终点回到起点,在经过的点不同的情况下最多能经过几个点 Sol 首先,问题可以转化为求两条互不相交的路径,使得点数最多 为了满足 ...
- 洛谷P4013 数字梯形问题(费用流)
题意 $N$行的矩阵,第一行有$M$个元素,第$i$行有$M + i - 1$个元素 问在三个规则下怎么取使得权值最大 Sol 我只会第一问qwq.. 因为有数量的限制,考虑拆点建图,把每个点拆为$a ...
- 洛谷 P4015 运输问题 【最小费用最大流+最大费用最大流】
s向仓库i连ins(s,i,a[i],0),商店向t连ins(i+m,t,b[i],0),商店和仓库之间连ins(i,j+m,inf,c[i][j]).建两次图分别跑最小费用最大流和最大费用最大流即可 ...
随机推荐
- error C2011: “Picture”:“struct”类型重定义
今天引用外来库时出现问题,也许是版本问题. 错误如下: .....\oursun\cincludes\quickdraw.h(309): error C2011: “Picture”:“struct” ...
- 【LoadRunner】场景执行报错“failed: WSA_IO_PENDING”
问题:性能测试场景执行报“failed: WSA_IO_PENDING”错误 解决方法: 添加web_set_sockets_option("OVERLAPPED_SEND", & ...
- jmeter正则表达式提取 引用
jmeter正则表达式token提取 例: 添加正则 配置 token正则表达式:"token":"(.+?)" 模板:$1$ 添加信息头管理器进行配置 需要t ...
- Selenium-java 中 对于下拉框 对于网页上的下拉框 如何定位
WebElement e1 = driver.findElement(By.cssSelector("#s_province")); Select se1 = new Select ...
- 微信小程序简单的数据表格及查询功能
简介: 此项目是一个前后端分离的小demo, 开发工具:idea+微信小程序开发工具 前端:界面布局样式和js的跳转 后端:依靠SpringBoot的业务逻辑层 项目的码云地址: https://gi ...
- Google Optimize 安装使用教程
Google Optimize 介绍 打开链接 https://optimize.google.com/optimize/signup/ 填入电邮地址后等待注册邀请 Google Optimize是什 ...
- Leetcode 516.最长回文子序列
最长回文子序列 给定一个字符串s,找到其中最长的回文子序列.可以假设s的最大长度为1000. 示例 1:输入: "bbbab" 输出: 4 一个可能的最长回文子序列为 " ...
- ActionContext和ServletActionContext小结
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息, ...
- js作用域的理解
script:自上而下 全局变量.全局函数 函数:由里到外 浏览器: “JS解析器” 1)“找一些东西”: var function 参数 a = undefine 所有的变量,在正式运行代码之前,都 ...
- node.js express 4.x 安装指南(Express不是内部或外部命令解决方案)
前几天express 推出了4.0,得知这个消息,自己尝试了一下,突然发现用以前的文档上的操作出现了各种问题.结果只能去看文档,现在在这个给大家分享下4.0版本的安装. 先说下如果需要用express ...