USACO Monthly Expense
洛谷 P2884 [USACO07MAR]每月的费用Monthly Expense
https://www.luogu.org/problem/P2884
POJ 3273 Monthly Expense
http://poj.org/problem?id=3273
题目描述
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.
输入输出样例
7 5 100 400 300 100 500 101 400
500
说明/提示
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.
二分答案基础题,详情参考我的上一篇博客,是同一道题,代码都是一样一样的。
https://www.cnblogs.com/fusiwei/p/11250988.html
#include<cstdio> #include<algorithm> using namespace std; int n,m,sum,ans,maxn; int a[100001]; bool check(int x) {int tot=0,cnt=0;for(int i=1;i<=n;i++){if(tot+a[i]<=x){tot+=a[i];continue;}tot=a[i];cnt++;}if(tot>0)cnt++;if(cnt<=m)return 1;elsereturn 0; } int main() {scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&a[i]);sum+=a[i];maxn=max(maxn,a[i]);}int l=maxn;int r=sum;while(l<=r){int mid=(l+r)>>1;if(check(mid))ans=mid,r=mid-1;elsel=mid+1;}printf("%d",ans);return 0; }
转载于:https://www.cnblogs.com/fusiwei/p/11251032.html
USACO Monthly Expense相关推荐
- 二分搜索 POJ 3273 Monthly Expense
题目传送门 1 /* 2 题意:分成m个集合,使最大的集合值(求和)最小 3 二分搜索:二分集合大小,判断能否有m个集合. 4 */ 5 #include <cstdio> 6 #incl ...
- 【POJ 3273】 Monthly Expense (二分)
[POJ 3273] Monthly Expense (二分) 一个农民有块地 他列了个计划表 每天要花多少钱管理 但他想用m个月来管理 就想把这个计划表切割成m个月来完毕 想知道每一个月最少花费多少 ...
- Monthly Expense【二分】
B - Monthly Expense POJ - 3273 Farmer John is an astounding accounting wizard and has realized he mi ...
- bzoj1639[Usaco2007 Mar]Monthly Expense 月度开支*
bzoj1639[Usaco2007 Mar]Monthly Expense 月度开支 题意: n天,每天有一个花费,现在要将它们分成连续的m段,要求所有段的总花费的最大值最小.求这个值.n,m≤10 ...
- BZOJ 1639: [Usaco2007 Mar]Monthly Expense 月度开支( 二分答案 )
直接二分答案然后判断. ----------------------------------------------------------------------------- #include&l ...
- bzoj 1639: [Usaco2007 Mar]Monthly Expense 月度开支(二分)
1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1057 Solve ...
- Monthly expense(二分)
又又又又是二分啦 憨憨桃子又来啦 题目链接:monthly expense 题目描述: Farmer John is an astounding accounting wizard and has r ...
- Monthly Expense(二分)
Monthly Expense Farmer John is an astounding accounting wizard and has realized he might run out of ...
- Monthly Expense POJ - 3273(二分最大值最小化)
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the ...
最新文章
- 扫描 VNC 的脚本
- ​“好师父”如何破解大学生就业难题
- eclipse中 properties文件编码问题
- 计算机死机的重启方法,使用“紧急重启”功能让电脑重启,解决电脑死机!
- java简单的死锁检测(转载线下代码)
- ApacheCN Linux 译文集 20211129 更新
- 心跳监测器 IHeartBeatChecker
- 总结CMS常见面试题
- PHP7.1安装memcaehd扩展
- cce是什么意思_CCE 是什么
- html页面上允许文字复制,网页上的文字无法复制?教你如何破除网页限制
- Android 直播调研
- 小菜学前端day02(学习笔记)
- 服务器c盘里面哪些是临时文件,别再让你系统产生的大量临时文件占用C盘了的方法...
- fir1截止频率计算_如果给定通带截止频率和阻带截止频率以及阻带最小衰减,如何用窗函数法设计线性相位低通滤波器?请写出设计...
- 计算机硬件希沃课件,希沃课件怎么转为ppt?
- java打印 X XXX XXXXX
- 有没有人拼团csdn学习会员~~
- 微信小程序如何开通支付功能?
- js 去掉字符串最后一个逗号