BZOJ【1639】: [Usaco2007 Mar]Monthly Expense 月度开支
1639: [Usaco2007 Mar]Monthly Expense 月度开支
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 700 Solved: 347
[Submit][Status][Discuss]
Description
Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的。他已经计算了他以后N(1<=N<=100,000)个工作日中每一天的花费moneyi(1<=moneyi<=10,000),他想要为他连续的M(1<=M<=N)个被叫做“清算月”的结帐时期做一个预算,每一个“清算月”包含一个工作日或更多连续的工作日,每一个工作日都仅被包含在一个“清算月”当中。 FJ的目标是安排这些“清算月”,使得每个清算月的花费中最大的那个花费达到最小,从而来决定他的月度支出限制。
Input
第一行:两个用空格隔开的整数:N和M
第2..N+1行:第i+1行包含FJ在他的第i个工作日的花费
Output
第一行:能够维持每个月农场正常运转的钱数
Sample Input
100
400
300
100
500
101
400
Sample Output
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#define maxn 100000+100
int a[maxn],n,m,ans;
bool pan(int q)
{
int sum=,tot=; //切记tot=1;
for(int i=;i<=n;++i)
{
if(sum+a[i]<=q) sum+=a[i];
else
{
sum=a[i];++tot;
}
if(tot>m||a[i]>q) return ;
}
return ;
}
int erfen(int p)
{
int l=,r=;
while(l<=r)
{
int mid=(l+r)>>;
if(pan(mid)) {
ans=mid;r=mid-;
}
else l=mid+;
}
return ans;
}
using namespace std;
int main()
{
freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
cin>>n>>m;
for(int i=;i<=n;++i) scanf("%d",&a[i]);
erfen(n);
cout<<ans;
return ;
}
BZOJ【1639】: [Usaco2007 Mar]Monthly Expense 月度开支的更多相关文章
- BZOJ 1639: [Usaco2007 Mar]Monthly Expense 月度开支( 二分答案 )
直接二分答案然后判断. ----------------------------------------------------------------------------- #include&l ...
- BZOJ 1639: [Usaco2007 Mar]Monthly Expense 月度开支
Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N<=100 ...
- bzoj 1639: [Usaco2007 Mar]Monthly Expense 月度开支【二分】
忘开long long了居然没WA 二分答案,枚举判断看最后需要的月份数是否小于等于要求的即可 #include<iostream> #include<cstdio> usin ...
- 1639: [Usaco2007 Mar]Monthly Expense 月度开支
1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 593 Solved: ...
- 【BZOJ】1639: [Usaco2007 Mar]Monthly Expense 月度开支(二分)
http://www.lydsy.com/JudgeOnline/problem.php?id=1639 同tyvj1359,http://www.cnblogs.com/iwtwiioi/p/394 ...
- BZOJ1639: [Usaco2007 Mar]Monthly Expense 月度开支
1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 529 Solved: ...
- 【二分答案】bzoj1639 [Usaco2007 Mar]Monthly Expense 月度开支
#include<cstdio> using namespace std; #define N 100001 int n,m,a[N]; bool check(int x) { int n ...
- bzoj 1637: [Usaco2007 Mar]Balanced Lineup
1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MB Description Farmer John ...
- Bzoj 1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 传递闭包,bitset
1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 323 Solved ...
随机推荐
- Windows10系统下查看mysql的端口号并修改
mysql的端口号默认是3306,初学者可能有时会忘记或者之前修改了默认的端口号,忘记了,或者很多时候我们一台电脑需要安装两个mysql或者想设置一个自己的喜欢的数字,那么接下来我们来看看如何查看或者 ...
- centos7安装phpstudy
操作系统:CentOS 7 x86_64 SSH登录工具:FinalSHell 2.9.7 一.安装phpstudy 1.下载完整版: wget -c http://lamp.phpstudy.net ...
- java 调用第三方系统时的连接代码-记录
前言:该文章主要是总结我在实际工作中遇到的问题,在调取第三方系统的时候出现的问题,算自己的总结.各位博友如果有什么建议或意见欢迎留言指正. 先将准备传入参数 再与第三方系统建立连接 再第三方系统处理后 ...
- 各种友(e)善(xin)数论总集(未完待续),从入门到绝望
目录 快速幂 扩展欧几里得 GCD 扩展欧几里得 同余系列 同余方程 同余方程组 一点想法 高次同余方程 BSGS exBSGS 线性筛素数 埃式筛 欧拉筛 欧拉函数 讲解 两道水题 法雷级数 可见点 ...
- HDU:3336-Count the string(next数组理解)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pr ...
- python之时间处理time模块
import time import datetime ''' print(time.time()) #返回当前系统时间戳 print(time.ctime()) #返回当前系统时间 print(ti ...
- 处理IE6下PNG图片透明背景问题
由于历史原因,IE较早的版本不支持PNG透明 可以支持GIF等的透明 由于png图片相对较小,所以很多网站还是青睐于PNG图片 最近就遇到这种情况,使用js和css滤镜来实现的与大家分享一下下: 首先 ...
- 【MySQL】资源列表
1.使用yum方式安装MySQL https://blog.csdn.net/zl570932980/article/details/78934601 2.安装Xtrabackup备份工具 https ...
- 【Scramble String】cpp
题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...
- 【Combination Sum 】cpp
题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C ...