bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
2024-10-18 21:23:34
http://www.lydsy.com/JudgeOnline/problem.php?id=4590
二分
这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发
最近是怎么了啊啊啊O(≧口≦)O
#include<cstdio>
#include<iostream> using namespace std; int n,m; int x[]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} int check(long long k)
{
long long now=;
int sum=;
for(int i=;i<=n;++i)
{
now+=x[i];
if(now>=k) sum++,now=;
else if(now<) now=;
}
return sum;
} int main()
{
freopen("autoac.in","r",stdin);
freopen("autoac.out","w",stdout);
read(n); read(m);
for(int i=;i<=n;++i) read(x[i]);
long long l=,r=1LL*n*1e9,tmp=-,mid;
int t;
while(l<=r)
{
mid=l+r>>;
t=check(mid);
if(t==m) tmp=mid,r=mid-;
else if(t>m) l=mid+;
else r=mid-;
}
if(tmp==-)
{
printf("-1");
return ;
}
cout<<tmp<<' ';
l=tmp,r=1LL*n*1e9;
while(l<=r)
{
mid=l+r>>;
t=check(mid);
if(t==m) tmp=mid,l=mid+;
else if(t>m) l=mid+;
else r=mid-;
}
cout<<tmp;
return ;
}
最新文章
- JavaScript - 基于CSS3动画的实现
- 本周psp
- Intellij Idea 14 使用jetty-maven-plugin配置运行web工程
- WordPress登陆页和后台面空白解决方法
- 过渡transitioin
- Visual C#编写3D游戏框架示例
- Hibernate中的多对多映射
- Unity3D研究院编辑器之脚本设置ToolBar
- poj3519
- 并发队列之:BlockingQueue和ConcurrentLinkedQueue
- github进行修改
- html 时间单位
- Match类解析
- MyBatis的三层级联和二层缓存
- 20180726 - Windows 10 Pro 下远程桌面连接提示“出现身份验证错误”
- Spring Cloud 微服务笔记(七) Zuul入门
- delphi 鼠标拖动
- 百万级开源MQTT消息服务器 搭建
- POI解析Excel代码
- SSH报错