洛谷—— 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]).建两次图分别跑最小费用最大流和最大费用最大流即可 ...
随机推荐
- oracle 迭代查询
Oracle 迭代查询, 以后台菜单作为示例 这是要准备的sql create table tbl_menu( id number primary key, parent_id , name ) no ...
- 【清华集训】小Y和地铁
图已挂,前往luogu 题目: 小 $\rm Y$ 是一个爱好旅行的 $\rm OIer$.一天,她来到了一个新的城市.由于不熟悉那里的交通系统,她选择了坐地铁.她发现每条地铁线路可以看成平面上的一条 ...
- 整理的一些Android开发类免费视频课程
1.Android实战淘宝网项目视频:http://edu.ibeifeng.com/view-index-id-248.html 2.Android滚动视差实现课程:http://edu.ibeif ...
- java面向对象之关键字,权限修饰符
1.关键字:this,static,package,importthis:1.表示对当前对象的引用!2.表示用类的成员变量,而非函数参数,注意在函数参数和成员变量同名是进行区分!其实这是第一种用法的特 ...
- Leetcode 561.数组拆分I
数组拆分 I 给定长度为 2n 的数组, 你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), ..., (an, bn) ,使得从1 到 n 的 min(ai, bi) 总 ...
- opendatasource问题
EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO EXEC sp_configure 'Ad Hoc Distributed ...
- 第四篇:python基础_4
本篇内容 名称空间与作用域 闭包函数 装饰器 迭代器 生成器 三元表达式 列表解析 生成器表达式 一. 名称空间与作用域 1.名称空间 存放名字的地方,准确的说名称空间是存放名字与变量值绑定关系的地方 ...
- [UOJ#132][BZOJ4200][luogu_P2304][NOI2015]小园丁与老司机
[UOJ#132][BZOJ4200][luogu_P2304][NOI2015]小园丁与老司机 试题描述 小园丁 Mr. S 负责看管一片田野,田野可以看作一个二维平面.田野上有 \(n\) 棵许愿 ...
- [nowcoder_Wannafly挑战赛4_F]线路规划
[nowcoder_Wannafly挑战赛4_F]线路规划 试题描述 Q国的监察院是一个神秘的组织. 这个组织掌握了整个帝国的地下力量,监察着Q国的每一个人. 监察院一共有 \(N\) 个成员,每一个 ...
- windows部分快捷键及terminal命令
切换任务: win+tab terminal命令 pwd:打印当前工作目录 hostname:获取我的计算机的网络名称 mkdir:创建目录 cd:更改目录 ls/ dir -R:列出目录下的文件 r ...