HDU 6231 (K-th Number)
题目链接:https://cn.vjudge.net/problem/HDU-6231
思路:二分+双指针;
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long int LL;
const int INF=2e9+1e8;
const int maxn=1e5+100;
int a[maxn],b[maxn];
int n,k;
LL m;
LL calc(int x) //计算区间第k大的数大于等于x的区间个数
{
LL ans=0;
int l=0,r=-1,num=0;
while(r<n)
{
if(num<k)
{
if(a[r+1]>=x) num++;
r++;
}
else
{
if(num==k) ans+=n-r;
if(a[l]>=x) num--;
l++;
}
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%lld",&n,&k,&m);
for(int i=0;i<n;i++)
scanf("%d",&a[i]),b[i]=a[i];
sort(b,b+n);
int len=unique(b,b+n)-b;
int l=0,r=len-1,ans=-1;
while(l<=r)
{
int mid=(l+r)>>1;
if(calc(b[mid])>=m) ans=b[mid],l=mid+1;
else r=mid-1;
}
printf("%d\n",ans);
}
return 0;
}
HDU 6231 (K-th Number)的更多相关文章
- 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 ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- HDU 6093 - Rikka with Number | 2017 Multi-University Training Contest 5
JAVA+大数搞了一遍- - 不是很麻烦- - /* HDU 6093 - Rikka with Number [ 进制转换,康托展开,大数 ] | 2017 Multi-University Tra ...
- hdu 6216 A Cubic number and A Cubic Number【数学题】
hdu 6216 A Cubic number and A Cubic Number[数学] 题意:判断一个素数是否是两个立方数之差,就是验差分.. 题解:只有相邻两立方数之差才可能,,因为x^3-y ...
- HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)
HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意: 给一个序列由 ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
- 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 ...
- HDU 1394 Minimum Inversion Number ( 树状数组求逆序数 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number ...
随机推荐
- Android 一个强大的图片选择器
看看下面的图片选择器,感觉很不错 http://www.jcodecraeer.com/a/anzhuokaifa/2017/0122/7083.html 看看下面的图片选择器,支持视频等 http: ...
- IOS ARC内存管理,提高效率避免内存泄露
本文转载至 http://blog.csdn.net/allison162004/article/details/38756263 Cocoa内存管理机制 (1)当你使用new.alloc.copy方 ...
- app 之间发送文件 ios
本文转载至 http://www.51094.com/?p=212 第一种: 发送一个正常的 pdf 文件,只要是能读取pdf 的都能得到响应 -(IBAction)openDocumentIn ...
- Gone Fishing(贪心)
Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...
- Spring标签@Aspect-实现面向方向编程(@Aspect的多数据源自动加载)——SKY
从Spring 2.0开始,可以使用基于schema及@AspectJ的方式来实现AOP.由于@Aspect是基于注解的,因此要求支持注解的5.0版本以上的JDK. 环境要求: 1. mybit ...
- 自动更新GeoIP数据库
#!/bin/bash if [ ! -d /usr/local/share/GeoIP ];then mkdir /usr/local/share/GeoIP fi if [ ! -d /usr/l ...
- ElasticSearch(三十)基于scoll+bulk+索引别名实现零停机重建索引
1.为什么要重建索引? 总结,一个type下的mapping中的filed不能被修改,所以如果需要修改,则需要重建索引 2.怎么zero time重建索引? 一个field的设置是不能被修改的,如果要 ...
- 【android】在Service的onStartCommand()中调用stopself()应该注意的问题
在Service的onStartCommand()中调用stopself()后并不会立马destroy掉service,而是等onStartCommand()运行完才destroy. public c ...
- go语言之并发编程 channel
前面介绍了goroutine的用法,如果有多个goroutine的话相互之间是如何传递数据和通信的呢.在C语言或者JAVA中,传输的方法包括共享内存,管道,信号.而在Go语言中,有了更方便的方法,就是 ...
- python+NLTK 自然语言学习处理六:分类和标注词汇一
在一段句子中是由各种词汇组成的.有名词,动词,形容词和副词.要理解这些句子,首先就需要将这些词类识别出来.将词汇按它们的词性(parts-of-speech,POS)分类并相应地对它们进行标注.这个过 ...