3486 ( Interviewe )RMQ
YaoYao decides to make the interview as follows. First he queues the interviewees according to their coming order. Then he cuts the queue into m segments. The length of each segment is
, which means he ignores the rest interviewees (poor guys because they comes late). Then, each segment is assigned to an interviewer and the interviewer chooses the best one from them as the employee.YaoYao’s idea seems to be wonderful, but he meets another problem. He values the ability of the ith arrived interviewee as a number from 0 to 1000. Of course, the better one is, the higher ability value one has. He wants his employees good enough, so the sum of the ability values of his employees must exceed his target k (exceed means strictly large than). On the other hand, he wants to employ as less people as possible because of the high salary nowadays. Could you help him to find the smallest m?
In the first line of each case, there are two numbers n and k, indicating the number of the original people and the sum of the ability values of employees YaoYao wants to hire (n≤200000, k≤1000000000). In the second line, there are n numbers v1, v2, …, vn (each number is between 0 and 1000), indicating the ability value of each arrived interviewee respectively.
The input ends up with two negative numbers, which should not be processed as a case.
7 100 7 101 100 100 9 100 100 110 110
-1 -1
We need 3 interviewers to help YaoYao. The first one interviews people from 1 to 3, the second interviews people from 4 to 6,
and the third interviews people from 7 to 9. And the people left will be ignored. And the total value you can get is 100+101+100=301>300.
题解 : RMQ
C++代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 200000 +9
#define MAXE 22
int h[MAXN],mmax[MAXN][MAXE];
int N,Q;
int L,R;
void RMQ_ST(){
for(int i=;i<=N;i++){
mmax[i][]=h[i]; }
int end_j=log(N+0.0)/log(2.0);
int end_i;
for(int j=;j<=end_j;j++){
end_i=N+-(<<j);
for(int i=;i<=end_i;i++){
mmax[i][j]=max(mmax[i][j-],mmax[i+(<<(j-))][j-]);
// mmin[i][j]=min(mmin[i][j-1],mmin[i+(1<<(j-1))][j-1]);
}
}
}
int QueryMax(int L,int R){ int k=log(R-L+1.0)/log(2.0);
return max(mmax[L][k],mmax[R-(<<k)+][k]);
} int main(){
while(~scanf("%d%d",&N,&Q)&&(N > || Q > )){
int maxx = ;
for(int i=;i<=N;i++){
scanf("%d",&h[i]);
maxx = max(h[i],maxx);
}
int m = ; RMQ_ST();
m = Q / maxx; int flag = ;
if(m == ) {
m = ;
flag = ;
goto out ;
}
for(;m <= N; m ++){
int res = ;
int sss = ; int s = N / m;
int i = ;
int j = m;
while(j--){
res += QueryMax(i ,i + s- );
i += s;
}
if(res > Q) {
flag = ;
break;
}
}
out :
if(!flag) printf("-1\n");
else
cout << m << endl; } return ;
}
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 RMQ
题意: 将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和 ...
- HDOJ 3486 Interviewe
人生中第一次写RMQ....一看就知道 RMQ+2分但是题目文不对题....不知道到底在问什么东西....各种WA,TLE,,RE...后就过了果然无论错成什么样都可以过的,就是 上层的样例 啊 I ...
- 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; + ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- [数据结构]RMQ问题小结
RMQ问题小结 by Wine93 2014.1.14 1.算法简介 RMQ问题可分成以下2种 (1)静态RMQ:ST算法 一旦给定序列确定后就不在更新,只查询区间最大(小)值!这类问题可以用倍增 ...
随机推荐
- 进度对话框QProgressDialog
继承于 QDialog import sys,time from PyQt5.QtWidgets import QApplication, QWidget,QPushButton,QProgress ...
- B1011. A+B 和 C
题目描述 给定区间[-2^63, 2^63]内的三个整数A.B 和 C,请判断A+B是否大于C 输入格式 第一行给出正整数T(≤10),即测试用例的个数.随后给出T组测试用例,每组占一行,顺序给出A. ...
- 利用BeautifulSoup爬去我爱我家的租房数据
因为之前对BeautifulSoup一直不是很熟悉,刚好身边的朋友同事在找房子,就想着能不能自己写个爬虫爬一下数据,因此就写了这个爬虫.基本都是边看书边写的,不过也没什么好讲的.直接粘代码了. # c ...
- linux运维、架构之路-nfs网络文件系统
一.nfs介绍 NFS是Network File System的缩写,是网络文件系统,它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录,主要存储用户上传的图片附件等信息. ...
- Vue在移动端App中使用的问题总结
1.客户端中弹出键盘使得fixed布局错乱 Vue 在移动端中使用,当弹出键盘时,fixed 布局的元素可能会被键盘顶起. 例子图示及解决方法参考:https://blog.csdn.net/qq_3 ...
- 又联考了一场,感觉自己好菜啊,T1没写出来,后来花了一个早上调试。QAQ。最后发现是个-1还有取模没打。。。TAT。。。难受极了!!!
简单的区间(interval) 题目描述: 样例输入: 样例1: 4 3 1 2 3 4 样例2: 4 2 4 4 7 4 样例输出: 样例1: 3 样例2: 6 提示: 时间限制:1000ms 空间 ...
- docker 安装MongoDB以及设置用户
MongoDB 是一个免费的开源跨平台面向文档的 NoSQL 数据库程序. 1.查看可用的 MongoDB 版本 访问 MongoDB 镜像库地址: https://hub.docker.com/_/ ...
- Spring Cloud Commons教程(一)普通抽象
诸如服务发现,负载平衡和断路器之类的模式适用于所有Spring Cloud客户端可以独立于实现(例如通过Eureka或Consul发现)的消耗的共同抽象层. @EnableDiscoveryClien ...
- java读取ldif文件并创建新的节点
所需jar包ldap.jar. jldap-4.3-source.jar http://www.java2s.com/Code/Jar/l/Downloadldapjar.htm 浏览器输入http: ...
- Xcode Server持续集成
这是一篇2017-11-12 年我还在 ezbuy 的一篇文章,时间过去很早了,最近在整理笔记的时候发现了, 同步过来,文章内容现在是否有效不确定,应该大差不差,读者仅做参考 最后更新 2017-11 ...