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 ...
随机推荐
- js页面可视区域懒加载
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 关于ECSHOP中sql注入漏洞修复
标签:ecshop sql注入漏洞修复 公司部署了一个ecshop网站用于做网上商城使用,部署在阿里云服务器上,第二天收到阿里云控制台发来的告警信息,发现ecshop网站目录下文件sql注入漏洞以及程 ...
- Ubuntu 设置静态ip地址
1. 找到文件并作如下修改: sudo vim /etc/network/interfaces 修改如下部分: auto eth0iface eth0 inet staticaddress 192.1 ...
- IDEA创建maven项目的web.xml头
使用IDEA创建maven项目骨架是webapp时,软件自动创建的web.xml文件是2.3版本的,不能使用el表达式,所以可以手动换成4.0的文件头. <?xml version=" ...
- JavaScript_11_验证
表单验证: JavaScript可用来在数据被送往服务器前对HTML表单中的输入数据进行验证 1. 是否填写了必填项目 2. 邮件地址是否合法 ... <form action="su ...
- POJ Charlie's Change 查理之转换(多重背包,变形)
题意: 给定身上的4种硬币,分别是1 ,5 ,10, 25面额各有多张,要求组成面额p的硬币尽可能多.输出组成p的4种硬币各自的数量. 思路: 多重背包,300+ms.用01背包+二进制的方法.记录下 ...
- redis的一些问题总结,转载自infoq
Redis是时下比较流行的Nosql技术.在优酷我们使用Redis Cluster构建了一套内存存储系统,项目代号蓝鲸.到目前为止集群有700+节点,即将达到作者推荐的最大集群规模1000节点.集群从 ...
- 2015 ACM/ICPC Asia Regional Changchun Online Pro 1008 Elven Postman (BIT,dfs)
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- js 获取当前年月日时分秒星期
$("#aa").click(function () { var date = new Date(); this.year = date.getFullYear(); this.m ...
- 7.Props向子组件传递数据
组件实例的作用域是孤立的.这意味着不能并且不应该在子组件的模板内直接引用父组件的数据. 可以使用 props 把数据传给子组件. for-child-msg="aaa" , fo ...