题意:

将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和大于\(k\)。求最小的\(m\)。

分析:

预处理RMQ,维护区间最大值。

然后二分\(m\),将每段区间最大值加起来判断即可。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = 200000 + 10;
const int logmaxn = 20; int n, k;
int a[maxn], d[maxn][logmaxn]; void init() {
for(int i = 0; i < n; i++) d[i][0] = a[i];
for(int j = 1; (1<<j) <= n; j++)
for(int i = 0; i + (1<<j) - 1 < n; i++)
d[i][j] = max(d[i][j-1], d[i+(1<<(j-1))][j-1]);
} int query(int L, int R) {
int k = 0;
while((1<<(k+1)) <= R-L+1) k++;
return max(d[L][k], d[R-(1<<k)+1][k]);
} bool check(int x) {
int l = n / x;
int tot = 0;
for(int i = 0; i < x; i++) {
tot += query(i * l, (i+1) * l - 1);
if(tot > k) return true;
}
return false;
} int main()
{
while(scanf("%d%d", &n, &k) == 2) {
if(n < 0 && k < 0) break; int sum = 0, Max = 0;
for(int i = 0; i < n; i++) {
scanf("%d", a + i);
sum += a[i];
Max = max(Max, a[i]);
} if(Max > k) { printf("1\n"); continue; }
if(sum <= k) { printf("-1\n"); continue; } init(); int ans = n, L = 1, R = n;
while(L < R) {
int mid = (L + R) / 2;
if(!check(mid)) L = mid + 1;
else R = mid;
}
printf("%d\n", L);
} return 0;
}

HDU 3486 Interviewe RMQ的更多相关文章

  1. hdu 3486 Interviewe (RMQ+二分)

    Interviewe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. HDU 3486 Interviewe

    题目大意:给定n个数的序列,让我们找前面k个区间的最大值之和,每个区间长度为n/k,如果有剩余的区间长度不足n/k则无视之.现在让我们找最小的k使得和严格大于m. 题解:二分k,然后求RMQ检验. S ...

  3. hdu 3484 Interviewe RMQ+二分

    #include <cstdio> #include <iostream> #include <algorithm> using namespace std; + ...

  4. 3486 ( Interviewe )RMQ

    Problem Description YaoYao has a company and he wants to employ m people recently. Since his company ...

  5. Interviewe HDU - 3486( 暴力rmq)

    面试n个人,可以分任意组数,每组选一个,得分总和严格大于k,问最少分几组 就是暴力嘛...想到就去写吧.. #include <iostream> #include <cstdio& ...

  6. Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)

    YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there ...

  7. HDOJ 3486 Interviewe

    人生中第一次写RMQ....一看就知道 RMQ+2分但是题目文不对题....不知道到底在问什么东西....各种WA,TLE,,RE...后就过了果然无论错成什么样都可以过的,就是 上层的样例 啊  I ...

  8. HDU 5726 GCD (RMQ + 二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...

  9. HDU 5289 Assignment rmq

    Assignment 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Description Tom owns a company and h ...

随机推荐

  1. 十六进制和ASCII之间的转换

    2.关于两个byte[]数组的合并: public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) { byte[] byte_3 = n ...

  2. 关于 hystrix 的异常 fallback method wasn't found

    典型如下: @HystrixCommand(fallbackMethod = "fallbackHi") public String getHi(String x) { Strin ...

  3. dos 删除文件夹 rd

    windows普通方法删除不了文件.文件夹?那么试试dos命令吧. rd的另外一个写法是rmdir,源自ReMakeDirectory.使用的方法也很简单:rd 文件夹名 即可,例如:rd test. ...

  4. CSS 利用border三角形绘制方法

    CSS 三角形绘制方法,这里面的transparent比较重要,有和没有影响很大: 原理:这个div是由4个三角形组成,每个三角对应一个border,隐藏其它3个border,就可以得到一个三角形. ...

  5. 一键部署LNMP堆栈Web应用基础架构

    https://market.azure.cn/Vhd/Show?vhdId=9852&version=10884 产品详情 产品介绍LEMP/LNMP 是指一组通常一起使用来运行动态网站或者 ...

  6. 转载《五大免费采集器哪个好,火车头,海纳,ET,三人行,狂人采集 》

    在目前的站长圈内,比较流行的采集工具有很多,但是总结起来,比较出名的免费的就这么几个:火车头,海纳,ET,三人行,狂人. 下面我们对这几款采集工具作一个简单的评比. 1.火车头 基本上人人都知道,那就 ...

  7. BZOJ 3232: 圈地游戏 分数规划+判负环

    3232: 圈地游戏 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 966  Solved: 466[Submit][Status][Discuss] ...

  8. 将Java应用部署到SAP云平台neo环境的两种方式

    方法1 - 使用Eclipse Eclipse里新建一个服务器: 服务器类型选择SAP Cloud Platform: 点Finish,成功创建了一个Server: Eclipse里选择要部署的项目, ...

  9. ABAP function group和Tomcat library重复加载问题

    ABAP ABAP help文档里对**LOAD-OF-PROGRAM"的关键字是这样描述的: This event keyword defines the program construc ...

  10. 《学习CSS布局》学习笔记

    近几天做了一个小的企业展示网站.虽然页面是在模板的基础上改的,但改的多了不熟悉CSS也很麻烦.正好我看到了学习CSS布局这个网站,于是补习了一下CSS知识. CSS的显示 CSS的元素分为两类:块级元 ...