题意:

将\(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. 使用jstack分析解决进程死锁问题

    项目启动后不久就会出现死锁的现象,一直不知道什么原因造成的,后来经过大神的指点,解决了这个问题. 流程如下: 1.环境jdk1.6以上: 2.linux下使用ps aux|grep tomcat 命令 ...

  2. 报错:Could not reserve enough space for object heap error

    windows命令行运行某个命令时出现: 解决办法: 设置开始->控制面板->系统和安全->系统->高级系统设置->环境变量->系统变量->新建: 变量名: ...

  3. jsonp, json区别

    JSONP由两部分组成: 回调函数和数据 回调函数是接收到响应时应该在页面中调用的函数,其名字一般在请求中指定. 数据是传入回调函数中的JSON数据. jsonp var script=documen ...

  4. Windows Azure 配置Active Directory 主机(3)

    步骤 4:在 CloudSite 中安装附加域控制器 1.登录到 YourVMachine,单击“开始”,键入“dcpromo”,然后按 Enter. 2.在“欢迎使用”页上,单击“下一步”. 3.在 ...

  5. 随记:UWP开发中怎么使当前页面拓展到标题栏

    public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); CoreAp ...

  6. [VC]ocx控件怎么屏蔽backspace的后退键

    <script Language=javascript> function   document.onkeydown()   {   if(window.event.keyCode   = ...

  7. 【转】HTTP Live Streaming直播(iOS直播)技术分析与实现

    HTTP Live Streaming直播(iOS直播)技术分析与实现 不经意间发现,大半年没写博客了,自觉汗颜.实则2012后半年,家中的事一样接着一样发生,实在是没有时间.快过年了,总算忙里偷闲, ...

  8. Nat Nanotechnol | 朱涛/陈春英等合作发现碳纳米管呼吸暴露后的延迟毒性导致小鼠原位乳腺肿瘤的多发性广泛转移

    碳纳米管(Carbon nanotube, CNT)是重要的一维纳米材料,由于其良好的力学.电学和化学性能,可用作超强纤维.隐身材料.大功率超级电容器.传感器等,在纳米材料.信息.光电.能源.传感及生 ...

  9. 剑指offer题目分类

    1. 链表 1. 从尾到头打印链表 2. 链表中倒数第k个结点 3. 反转链表 4. 合并两个排序的链表 5. 复杂链表的复制 6. 复杂链表的复制 7. 两个链表的第一个公共结点 8. 链表中环的入 ...

  10. tomcat - 自带日志的区分

    在tomcat 中,logs文件夹下会存放着一些tomcat自带的日志文件,其中有三种文件: 1 > localhost_access_log.2017-12-28 文件,它用来记录tomcat ...