K-th Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 599    Accepted Submission(s): 234

Problem Description
Alice are given an array A[1..N] with N numbers.

Now Alice want to build an array B by a parameter K as following rules:

Initially, the array B is empty. Consider each interval in array A. If the length of this interval is less than K, then ignore this interval. Otherwise, find the K-th largest number in this interval and add this number into array B.

In fact Alice doesn't care each element in the array B. She only wants to know the M-th largest element in the array B. Please help her to find this number.

 
Input
The first line is the number of test cases.

For each test case, the first line contains three positive numbers N(1≤N≤105),K(1≤K≤N),M. The second line contains N numbers Ai(1≤Ai≤109).

It's guaranteed that M is not greater than the length of the array B.

 
Output
For each test case, output a single line containing the M-th largest element in the array B.
 
Sample Input
2
5 3 2
2 3 1 5 4
3 3 1
5 8 2
 
Sample Output
3
2
 
Source
题意:
大小为n的a数组,把其中所有的长度不小于k的区间中第k大的数加入到b数组,最后求b数组中的m大的数

输入:
n,k,m
a[1~n];
代码:
//m要用long long 啊。
//二分答案x,然后尺取。找到有多少个区间存在至少k个大于等于x的数,如果这样的区间数不少于m个就说明第m大的数
//比x大,因此有单调性。尺取区间[l,r]中有k个不小于x的数那么会有n-r+1个符合的区间。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int MAXN=;
int n,k,a[MAXN];
ll m;
bool solve(int x)
{
ll sum=;
int tmp=,l=,r=;
while(){
while(tmp<k){
++r;
if(r>n) break;
if(a[r]>=x) tmp++;
}
if(r>n) break;
sum+=(n-r+);
if(a[l]>=x) tmp--;
l++;
}
if(sum>=m) return ;
return ;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%lld",&n,&k,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int l=,r=1e9,ans=;
while(l<=r){
int mid=(l+r)>>;
if(solve(mid)) { ans=mid;l=mid+; }
else r=mid-;
}
printf("%d\n",ans);
}
return ;
}
 

HDU 6231的更多相关文章

  1. hdu 6231 -- K-th Number(二分+尺取)

    题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...

  2. HDU - 6231 K-th Number (2017CCPC哈尔滨站 二分+尺取法)

    Alice are given an array A[1..N] with N numbers. Now Alice want to build an array B by a parameter K ...

  3. HDU - 6231:K-th Number (不错的二分)

    Alice are given an array A[1..N]A[1..N] with NN numbers. Now Alice want to build an array BB by a pa ...

  4. HDU 6231 (K-th Number)

    题目链接:https://cn.vjudge.net/problem/HDU-6231 思路:二分+双指针: #include <stdio.h> #include <iostrea ...

  5. HDU 6231 (二分+双指针)

    题意:给一个长度为n的数组,问在由这个数组的所有的区间第k小组成B数组中,第m大元素是多少 解法:这题较难的地方在于转化思维.如果去求所有区间的第k小,最坏复杂度是O(n*n)肯定超时. 这题正确的解 ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. django之基本配置

    Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...

  2. dobule运算

    DecimalFormat df = new DecimalFormat("0.00"); double rate = (warnMonNum/totalCustCount)*10 ...

  3. ORACLE中查询被锁定的表,以及如何解锁

    http://www.cnblogs.com/weiyi1314/p/6813325.html

  4. 互评Beta版本——杨老师粉丝群——Pinball

    互评beta版本    杨老师粉丝群——<PinBall> 一.基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论作品的选题 (1)N(Need,需求) 随着年龄的增长, ...

  5. 20162314 Experiment 2 - Tree

    Experiment report of Besti course:<Program Design & Data Structures> Class: 1623 Student N ...

  6. Linux环境下Web环境搭建——Nginx

    1.安装依赖 yum -y install make gcc gcc-c++ ncurses-devel  ##编译环境 yum -y install zlib zlib-devel openssl ...

  7. Java文件写入时是否覆盖

    这个是和服务器读数据结合着来的,是向服务器文件写数据,这就碰到了是否覆盖以前写的数据的问题,看FileWriter();的参数后面的参数名叫append,用词典查是附加的意思,灵机一动,改成false ...

  8. HTML和CSS <h1> --1-- <h1>

    Html和CSS的关系 学习web前端开发基础技术需要掌握:HTML.CSS.JavaScript语言.下面我们就来了解下这三门技术都是用来实现什么的: 1. HTML是网页内容的载体.内容就是网页制 ...

  9. Android 目录结构

    Android目录结构中,values目录下对应的是应用程序所需要的数据,网上看到了一个包含values-v11等values-*的写法. 是为了进行分辨率的自适应????????? 因为还没有涉及到 ...

  10. 反爬虫之JS反编译:PyExecJS

    PyExecJS是python运行JavaScript代码的包 安装: pip install  PyExecJS (或者easy_install PyExecJS) 依赖:  需要有执行JS的程序, ...