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开源项目——小白全攻略 (转)
转自:打造一个高逼格的android开源项目 小引子 在平时的开发过程中,我们经常会查阅很多的资料,最常参考的是 github 的开源项目.通常在项目的主页面能看到项目的简介和基本使用,并且时不时能看 ...
- python基础-------python2.7教程学习【廖雪峰版】(二)
2017年6月7日14:59:27任务: 看完python基础1.计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文 ...
- python语言特性-------python2.7教程学习【廖雪峰版】(一)
开始学习廖雪峰的py2.7教程: 2017年6月5日12:54:28 笔记: 廖雪峰python2.7教程1.用任何编程语言来开发程序,都是为了让计算机干活. 2.Python是一种相当高级的语言. ...
- leetCode 57.Insert Interval (插入区间) 解题思路和方法
Insert Interval Given a set of non-overlapping intervals, insert a new interval into the intervals ...
- ubuntu14.04 desktop 32-bit kvm装windows xp
经过这几天来的折腾,总算是在ubuntu14.04用kvm装上了xp, 看不少的的贴,也绕了不少的圈,总的来说,非常感谢CSDN上的"上善若水75",看着他写的一个分类" ...
- eclipse同一个工作空间下分开多个项目
在Package Explorer顶部的右侧有有机表图标按钮,点击倒三角 Top Level Elements->Working Set.此时就会发现,很多项目会自动纳入一个文件夹,这个文件夹的 ...
- 使用PLSQL客户端导入导出数据库
本文主要介绍如何使用SQL Developer工具来实现备份数据库.数据导出等操作,然后实现Oracle对象导入数据等操作 1 导出数据库对象 在PL/SQL Developer的菜单Tools=&g ...
- date_default_timezone_get():
[Symfony\Component\Debug\Exception\ContextErrorException] Warning: date_default ...
- htop的使用
htop是top的增强版本.官网地址: http://hisham.hm/htop/ 这网站比较...... 实验环境: [root@miyan ~]# cat /etc/redhat-release ...
- pymysql插入datetime类型
第一种 create_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 第二种 update_time=time ...