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. 输入一个URL到页面呈现其中发生的过程-------http过程详解

    在我们点击一个网址,到它能够呈现在浏览器中,展示在我们面前,这个过程中,电脑里,网络上,究竟发生了什么事情. 服务器启动监听模式 那我们就开始了,故事其实并不是从在浏览器的地址栏输入一个网址,或者我们 ...

  2. Daily Scrum (2015/11/6)

    今晚除了玉钟焕的其他成员在一起开了个短会.讨论有关添加新功能以及一些BUG问题.由于时间原因,我们本想把动态爬取功能留到第二个迭代中,但是现在目前时间还够,我们便一起对这一功能的讨论和实现进行分析. ...

  3. 团队博客作业Week3 --- 项目选择&&需求疑问

    项目选择 经过团队内所有成员一致探讨,我们团队选择完善和改进之学霸系统的第二个子模块,即:网站内容结构定义和数据处理.具体的要求如下:(摘自Xueba系统项目需求) 网站内容结构定义和数据处理(Con ...

  4. object-oriented first work

    前言:在星期三的第一次面向对象程序设计课,遇见我们的栋哥,初次见面,发现老师的幽默.....下课后,就给我们一道作业题目... 作业要求:Create a program that asks for ...

  5. C#设置代码只在调试模式下执行

    获取一个值,它指示调试器是否已附加到进程. 命名空间:Namespace:System.Diagnostics if (Debugger.IsAttached) { Response.Write(&q ...

  6. 福大软工 · 第七次作业 - 需求分析报告(404 Note Found队)

    目录 组队后的团队项目的整体计划安排 项目logo及思维导图 项目logo 思维导图 产品思维导图 产品思维导图-引导 产品思维导图-后端数据处理.存储 产品思维导图-短信识别 产品思维导图-智能分析 ...

  7. [51单片机] Keil C51中变量的使用方法详解

    引言    8051内核单片机是一种通用单片机,在国内占有较大的市场份额.在将C语言用于51内核单片机的研究方面,Keil公司做得最为成功.由于51内核单片机的存储结构的特殊性,Keil C51中变量 ...

  8. python基础(六)python操作excel

    一.python操作excel,python操作excel使用xlrd.xlwt和xlutils模块,xlrd模块是读取excel的,xlwt模块是写excel的,xlutils是用来修改excel的 ...

  9. 利用ceye中的dns来获取数据

    安恒杯的一道命令执行题目 查看,存在robots.txt文件 查看index.txt文件,存在where_is_flag.php文件 使用cat没有任何回显 可以使用ceye平台利用dns记录内容,网 ...

  10. getResource()的使用总结 ;

    1.通过ClassLoader来加载getResource()时不需要加 "/" 因为source是从main开始的; Thread.currentThread().getCont ...