HDU 3486 Interviewe RMQ
题意:
将\(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的更多相关文章
- hdu 3486 Interviewe (RMQ+二分)
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 3486 Interviewe
题目大意:给定n个数的序列,让我们找前面k个区间的最大值之和,每个区间长度为n/k,如果有剩余的区间长度不足n/k则无视之.现在让我们找最小的k使得和严格大于m. 题解:二分k,然后求RMQ检验. S ...
- hdu 3484 Interviewe RMQ+二分
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; + ...
- 3486 ( Interviewe )RMQ
Problem Description YaoYao has a company and he wants to employ m people recently. Since his company ...
- Interviewe HDU - 3486( 暴力rmq)
面试n个人,可以分任意组数,每组选一个,得分总和严格大于k,问最少分几组 就是暴力嘛...想到就去写吧.. #include <iostream> #include <cstdio& ...
- Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there ...
- HDOJ 3486 Interviewe
人生中第一次写RMQ....一看就知道 RMQ+2分但是题目文不对题....不知道到底在问什么东西....各种WA,TLE,,RE...后就过了果然无论错成什么样都可以过的,就是 上层的样例 啊 I ...
- HDU 5726 GCD (RMQ + 二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...
- HDU 5289 Assignment rmq
Assignment 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Description Tom owns a company and h ...
随机推荐
- 值类型 VS 引用类型~
问 题 值 类 型 引 用 类 型 这个类型分配在哪里? 分配在栈上 分配在托管堆上 变量是怎么表示的? 值类型变量是局部复制 引用类型变量指向被分配得实例所占的内存 基类型是什么? 必须 ...
- 单个页面Request编码方式的改变,无需改动Web.config~
搞一个东西,从别人的接口接一段中文,URL传输,怎么都有乱码~~ 得到对方的编码方式是gb2312,于是用HttpUtility.UrlDecode(_smssend_content, System. ...
- fastjson格式化输出内容
引入fastjson <!--fastjson--><dependency> <groupId>com.alibaba</groupId> <ar ...
- 利用C#脚本来处理Excel
废不多,直入正题. 所需环境:安装了Windows操作系统和Office软件的电脑一台. 开发语言:C# 开发需求:1.利用C#脚本读取Excel .xlsx文件 2.将程序中的数据存储到.csv文件 ...
- Vuforia切换回识别场景后黑屏解决
使用Vuforia SDK开发时,如果从其他非识别场景切换回识别场景,可能会出现黑屏问题. 解决方法是在切换到其他场景时,先将当前场景的Tracker信息全部Stop.代码如下: IEnumerato ...
- HDU 5489 Removed Interval (LIS,变形)
题意: 给出一个n个元素的序列,要求从中删除任一段长度为L的连续子序列,问删除后的LIS是多少?(n<=10w, L<=n ,元素可能为负) 思路: 如果会O(nlogn)求普通LIS的算 ...
- 洛谷——普及练习场 普及组选手可冲刺训练,提高组选手亦可在此巩固基础。(Loading...)
简单的模拟 关卡2-1,6 道题 开始普及组的训练!所谓模拟,就是直接根据题意编写,思维难度简单. //T1 铺地毯 #include <cstdio> #define N 10005 i ...
- 如何在Sierra运行 Specials K 的patch
https://github.com/ApolloZhu/CORE-Keygen-and-Special-K-for-Sierra-Utility/blob/master/Special%20K%20 ...
- 第011课_串口(UART)的使用
from: 第011课_串口(UART)的使用 第001节_辅线1_硬件知识_UART硬件介绍 1. 串口的硬件介绍 UART的全称是 Universal Asynchronous Receiver ...
- python_99_面向对象多态
#多态:一种接口,多种实现.主要作用:实现接口重用 #方法1: class Animal(object): def __init__(self,name): self.name=name class ...