洛谷 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.

输入输出样例

输入 #1复制

7 5
100
400
300
100
500
101
400

输出 #1复制

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相关推荐

  1. 二分搜索 POJ 3273 Monthly Expense

    题目传送门 1 /* 2 题意:分成m个集合,使最大的集合值(求和)最小 3 二分搜索:二分集合大小,判断能否有m个集合. 4 */ 5 #include <cstdio> 6 #incl ...

  2. 【POJ 3273】 Monthly Expense (二分)

    [POJ 3273] Monthly Expense (二分) 一个农民有块地 他列了个计划表 每天要花多少钱管理 但他想用m个月来管理 就想把这个计划表切割成m个月来完毕 想知道每一个月最少花费多少 ...

  3. Monthly Expense【二分】

    B - Monthly Expense POJ - 3273 Farmer John is an astounding accounting wizard and has realized he mi ...

  4. bzoj1639[Usaco2007 Mar]Monthly Expense 月度开支*

    bzoj1639[Usaco2007 Mar]Monthly Expense 月度开支 题意: n天,每天有一个花费,现在要将它们分成连续的m段,要求所有段的总花费的最大值最小.求这个值.n,m≤10 ...

  5. BZOJ 1639: [Usaco2007 Mar]Monthly Expense 月度开支( 二分答案 )

    直接二分答案然后判断. ----------------------------------------------------------------------------- #include&l ...

  6. bzoj 1639: [Usaco2007 Mar]Monthly Expense 月度开支(二分)

    1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1057  Solve ...

  7. Monthly expense(二分)

    又又又又是二分啦 憨憨桃子又来啦 题目链接:monthly expense 题目描述: Farmer John is an astounding accounting wizard and has r ...

  8. Monthly Expense(二分)

    Monthly Expense Farmer John is an astounding accounting wizard and has realized he might run out of ...

  9. Monthly Expense POJ - 3273(二分最大值最小化)

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

最新文章

  1. 扫描 VNC 的脚本
  2. ​“好师父”如何破解大学生就业难题
  3. eclipse中 properties文件编码问题
  4. 计算机死机的重启方法,使用“紧急重启”功能让电脑重启,解决电脑死机!
  5. java简单的死锁检测(转载线下代码)
  6. ApacheCN Linux 译文集 20211129 更新
  7. 心跳监测器 IHeartBeatChecker
  8. 总结CMS常见面试题
  9. PHP7.1安装memcaehd扩展
  10. cce是什么意思_CCE 是什么
  11. html页面上允许文字复制,网页上的文字无法复制?教你如何破除网页限制
  12. Android 直播调研
  13. 小菜学前端day02(学习笔记)
  14. 服务器c盘里面哪些是临时文件,别再让你系统产生的大量临时文件占用C盘了的方法...
  15. fir1截止频率计算_如果给定通带截止频率和阻带截止频率以及阻带最小衰减,如何用窗函数法设计线性相位低通滤波器?请写出设计...
  16. 计算机硬件希沃课件,希沃课件怎么转为ppt?
  17. java打印 X XXX XXXXX
  18. 有没有人拼团csdn学习会员~~
  19. 微信小程序如何开通支付功能?
  20. js 去掉字符串最后一个逗号

热门文章

  1. 读代码比写代码难,真的?
  2. html防微信抢红包,如何实现仿微信抢红包
  3. 赏赐的是耶和华,收取的也是耶和华
  4. 《投资要义》书中的精髓:成功投资的要义在于低估值买入、分散化投资以及不深度研究个股。
  5. 你了解吗?评估活跃用户更恰当的指标是“周用户构成”(WAU Model)
  6. PowerMILL宏自动化编程教程
  7. 初学者C++面向对象程序设计概念全总结最全的概念总结
  8. 使用ceph的文件存储CephFS
  9. 大话重构连载11:小步快跑是这样玩的
  10. numpy 基本操作