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 ...
随机推荐
- bootstrat 设置 select option 选项的值
<script> /** //把textarea替换成一个编辑器 UE.getEditor('22upTips',{ initialFrameWidth:"80%", ...
- 程序包 javax.servlet 不存在 解决办法
其原因是java编译器没有找到软件包javax.servlet. 下载servlet.jar放到lib下没有效果,后发现需要在jdk中添加,如下: 解决办法: 从tomcat lib目录下拷贝一个se ...
- linux卸载一个源码包安装的软件的流程
完全卸载memcached的方法(CentOS) 我的大内存vps(centos系统)曾经安装过memcached,想给论坛提速,实际上不但没有明显效果,反倒耗费内存,看着碍眼,于是想卸载,于是网上各 ...
- PHP新手必学之刚进公司装环境
由于今天去一家公司做项目,又重新的装了一遍所熟悉的PHP环境,所以记录下来,总结下. PHP环境主要: PHPstudy(apache+mysql+php)+phpstorm+navicate 解释: ...
- 关于PHP反射
本文实例讲述了PHP反射机制原理与用法.分享给大家供大家参考,具体如下: 反射 面向对象编程中对象被赋予了自省的能力,而这个自省的过程就是反射. 反射,直观理解就是根据到达地找到出发地和来源.比如,一 ...
- 【BZOJ3060】[Poi2012]Tour de Byteotia 并查集
[BZOJ3060][Poi2012]Tour de Byteotia Description 给定一个n个点m条边的无向图,问最少删掉多少条边能使得编号小于等于k的点都不在环上. Input ...
- Residual (numerical analysis)
In many cases, the smallness of the residual means that the approximation is close to the solution, ...
- Full卷积 Same卷积 Vaild卷积
- 修改maven的war包生成路径
因为要配合jenkins,所以控制了war包的生成目录: <plugins> <!--打war包到指定的目录下 --> <plugin> <groupId&g ...
- Android笔记之GridView
完整Demo链接:https://pan.baidu.com/s/1d_G9aCwBxpiYQcdQhwSDDw,提取码:5deh 效果图 activity_main.xml <?xml ver ...