嘟嘟嘟




这题就比较水了,毕竟只评了个蓝。




想一下发现满足单调性,所以可以二分找最大值。

但是最小值怎么办?刚开始我很zz的以为只要把判断条件从大于等于改成小于等于就行了,后来发现根本不对。

想了想因为最小值和最大值之间一定是一段答案为\(k\)的区间,所以可以二分找最小值:如果当前答案不等于\(m\),就向右二分,否则向左二分。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e5 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n, m;
ll a[maxn], Max;
In bool judge1(ll x)
{
ll cnt = 0; ll tot = 0;
for(int i = 1; i <= n; ++i)
{
tot = max(1LL * 0, tot + a[i]);
if(tot >= x) ++cnt, tot = 0;
}
return cnt >= m;
}
In bool judge2(ll x)
{
ll cnt = 0; ll tot = 0;
for(int i = 1; i <= n; ++i)
{
tot = max(1LL * 0, tot + a[i]);
if(tot >= x) ++cnt, tot = 0;
}
return cnt == m;
} int main()
{
// freopen("1.in", "r", stdin);
n = read(), m = read();
for(int i = 1; i <= n; ++i) a[i] = read();
ll L = 0, R = 1e14;
while(L < R)
{
ll mid = (L + R + 1) >> 1;
if(judge1(mid)) L = mid;
else R = mid - 1;
}
if(!L || !judge2(L)) {puts("-1"); return 0;}
Max = L;
L = 1, R = Max;
while(L < R)
{
ll mid = (L + R) >> 1;
if(judge2(mid)) R = mid;
else L = mid + 1;
}
write(L), space, write(Max), enter;
return 0;
}

[SHOI2015]自动刷题机的更多相关文章

  1. BZOJ_4590_[Shoi2015]自动刷题机_二分答案

    BZOJ_4590_[Shoi2015]自动刷题机_二分答案 Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动 刷题 ...

  2. BZOJ4590 Shoi2015 自动刷题机 【二分】

    BZOJ4590 Shoi2015 自动刷题机 Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机–一种可以自动AC题目的神秘装置.自动刷题机刷题的方式非常简 ...

  3. 【BZOJ4590】[Shoi2015]自动刷题机 二分

    [BZOJ4590][Shoi2015]自动刷题机 Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动刷题机刷题的方式 ...

  4. bzoj4590: [Shoi2015]自动刷题机(二分答案)

    4590: [Shoi2015]自动刷题机 题目:传送门 题解: 很明显的一道二分题. 对于二分性的判断:如果n越大,那么AC的题就越少,n越小,AC的题就越多,那么最大最小值都满足单调性,直接瞎搞. ...

  5. 洛谷 P4343 [SHOI2015]自动刷题机

    思路 二分答案 显然的二分答案,但是因为二分判定条件 \(\text{wa}\) 了好几遍-- 可以发现,\(n\) 越大,\(k\) 就越小,所以答案是有单调性的,因此可以用两个二分,一次求最大值, ...

  6. COGS2642 / Bzoj4590 [Shoi2015]自动刷题机

    Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 906  Solved: 321 Description 曾经发明了信号增幅仪的发明家SHTSC又公开了 ...

  7. luogu P4343 [SHOI2015]自动刷题机 |二分答案

    题目描述 曾经发明了信号增幅仪的发明家 SHTSC 又公开了他的新发明:自动刷题机--一种可以自动 AC 题目的神秘装置. 自动刷题机刷题的方式非常简单:首先会瞬间得出题目的正确做法,然后开始写程序. ...

  8. BZOJ4590: [Shoi2015]自动刷题机

    显然看着就是二分,仔细看的话显然刷的题数随n增大单调不升. 挂了一发是因为无解输出一个-1而不是两个…… #include<cstdio> #include<algorithm> ...

  9. BZOJ4590——[Shoi2015]自动刷题机

    1.题意:题意很简洁吧,就不概括了 2.分析:我思考了半天,我猜答案满足单调...没敢写,看了题解去问Claris为啥单调,Claris一句话" 因为n越大明显不可能做更多题 ", ...

随机推荐

  1. Asp.net生命周期与Http协议

    Http协议,底层的东西还是不是特别熟悉,感觉要经过沉淀之后才能理解这些东西吧 1.Asp.net生命周期 Asp.net生命周期: 从发起请求开始,到IIS进行处理的全部过程,然后再到获取结果 当请 ...

  2. 三问助你Debug

    译者按: Debug也要三省吾身! 原文: Three Questions About Each Bug You Find 译者: Fundebug 为了保证可读性,本文采用意译而非直译.另外,本文版 ...

  3. POJ1201 Intervals(差分约束)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 10966 Description You ...

  4. django请求和响应

    本文转载自https://blog.csdn.net/xiaogeldx/article/details/88096341 HttpRequest对象 服务器接收到http协议的请求后,会根据报文创建 ...

  5. RabbitMQ 在 web 页面 创建 exchange, queue, routing key

    这里只是为了展示, 在实际开发中一般在消费端通过 注解来自动创建 消费端: https://www.cnblogs.com/huanggy/p/9695934.html 1, 创建 Exchange ...

  6. RabbitMQ 环境搭建

    安装基础环境 yum install net-tools yum install yum yum install gcc glibc-devel make ncurses-devel openssl- ...

  7. 让bind函数支持IE8浏览器的方法

    bind函数在IE8下是不支持的,只需要在你的js文件中加入如下代码就可以支持IE8 //让bind函数支持IE8 if (!Function.prototype.bind) { Function.p ...

  8. 全参考视频质量评价方法(PSNR,SSIM)以及与MOS转换模型

    转载处:http://blog.csdn.NET/leixiaohua1020/article/details/11694369 最常用的全参考视频质量评价方法有以下2种: PSNR(峰值信噪比):用 ...

  9. android网页打印,安卓网页打印,h5页面打印,浏览器打印,js打印工具

    Android设备打印比较麻烦,一般设备厂商都提供原生app开发的SDK,我们web开发者为难了,不会原生开发啊 给大家提供一个思路,实现web加壳,利用打印浏览器实现 简单来说就是把我们的web页面 ...

  10. The log scan number (620023:3702:1) passed to log scan in database 'xxxx' is not valid

    昨天一台SQL Server 2008R2的数据库在凌晨5点多抛出下面告警信息: The log scan number (620023:3702:1) passed to log scan in d ...