bzoj 1639: [Usaco2007 Mar]Monthly Expense 月度开支【二分】
忘开long long了居然没WA
二分答案,枚举判断看最后需要的月份数是否小于等于要求的即可
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100005;
int n,m,a[N],l,r,ans;
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
bool ok(int mid)
{
int con=1,sum=0;
for(int i=1;i<=n;i++)
{
if(sum+a[i]>mid)
sum=a[i],con++;
else
sum+=a[i];
}
return con<=m;
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)
a[i]=read(),l=max(l,a[i]),r+=a[i];
while(l<=r)
{
int mid=(l+r)>>1;
if(ok(mid))
r=mid-1,ans=mid;
else
l=mid+1;
}
printf("%d\n",ans);
return 0;
}
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 ...
- 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 ...
- BZOJ【1639】: [Usaco2007 Mar]Monthly Expense 月度开支
1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 700 Solved: ...
- 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 ...
随机推荐
- python 爬虫示例,方便日后参考
参考网址:https://zhuanlan.zhihu.com/p/32037625 def getOneMoviesInfo(Mid,url): import requests from lxml ...
- 一个WebLoad 脚本范例
//initial the Agenda function InitAgenda(){ wlGlobals.SaveHeaders = true; wlGlobals.SaveSour ...
- Just a Hook-HDU1698(线段树求区间)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge’s meat ...
- 2017-10-02-morning
T1 一道图论神题(god) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图 ...
- Android之AssetManager使用
1. 获取AssetManager AssetManager assetManager = context.getAssets(); 2. 列出assets文件夹下全部文件 String[] file ...
- JAVA OO之 类、对象、包
类 类是具有相同属性和行为的一组对象的集合. public class HomeWork1 { public static void main(String[] args) { MyPhone mp= ...
- list.ensureCapacity竟然会变慢
list.ensureCapacity竟然会变慢 jdk1.8 应该是做了优化了: public class Test10 { public static void main(String[] arg ...
- [AngularJS] Store the entry url and redirect to entry url after Logged in
For example when a outside application need to visit your app address: https://www.example.com/#/lob ...
- Android Studio 1.x 使用问题汇总
Android Studio是谷歌于13年I/O大会推出的Android开发环境,基于IntelliJ IDEA. 类似 Eclipse ADT,Android Studio 提供了集成的Androi ...
- String类的四个默认成员函数
优化版的拷贝构造函数,先创建一个暂时实例tmp,接着把tmp._ptr和this->_ptr交换,因为tmp是一个局部变量.程序执行到该函数作用域外,就会自己主动调用析构函数.释放tmp._pt ...