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. [linux] lsyncd同步工具

    环境说明: 192.168.56.101 同步源 192.168.56.102 同步目标 操作系统centos 7 lsyncd项目地址:https://github.com/axkibe/lsync ...

  2. Homebrew -- 安装与使用

    使用 React Native,必须安装的依赖有:Node.Watchman 和 React Native 命令行工具以及 Xcode. 推荐使用Homebrew来安装 Node 和 Watchman ...

  3. map的运用

    一.map是一种关联容器,支持高效的查找和访问 map中的元素是一些关键字-值(key-value)对: 关键字起索引作用: 值表示与索引相关联的数据. 关联容器中元素是根据关键字存储的,故其不支持位 ...

  4. Scrum立会报告+燃尽图(Final阶段第一次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2480 项目地址:https://coding.net/u/wuyy694 ...

  5. ModelAndView在页面上取值时value="{contextConfigLocation=<NONE>}"

    后台: mv.getModel().put("initParam", 1); 页面: <input type="hidden" id="init ...

  6. No.1000_第五次团队会议

    光辉的一夜 今夜注定是不平凡的一夜.是崔强同学伟大的一夜. 昨天因为实验室项目,我刚上完编译课就被学院叫走去做项目,当时我就很无奈,因为说好了要和崔强一起实现下午的前端,他写界面我写底层逻辑,这样我们 ...

  7. selenium之鼠标事件

    1.鼠标悬停火狐版本51,selenium版本3ActionChains(driver).move_to_element(above).perform()执行代码时,报错:selenium.commo ...

  8. Unity3D游戏开发——访问集中式共享模块的设计模式

    什么是设计模式 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类的.代码设计经验的总结.设计模式是开发人员在开发过程中面临的一般问题的解决方案,这些解决方案是众多开发人 ...

  9. 通过cmd命令安装、卸载、启动和停止Windows Service(InstallUtil.exe)

    步骤: 1.运行--〉cmd:打开cmd命令框 2.在命令行里定位到InstallUtil.exe所在的位置 InstallUtil.exe 默认的安装位置是在C:/Windows/Microsoft ...

  10. PHP-时间函数

    1.时间格式化函数date(format,timestamp) format 时间格式 timestamp 时间戳 下面列出了一些常用于日期的字符: d - 表示月里的某天(01-31) m - 表示 ...