HDU 6231
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
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.
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.
//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的更多相关文章
- 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 - 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 6231 (K-th Number)
题目链接:https://cn.vjudge.net/problem/HDU-6231 思路:二分+双指针: #include <stdio.h> #include <iostrea ...
- HDU 6231 (二分+双指针)
题意:给一个长度为n的数组,问在由这个数组的所有的区间第k小组成B数组中,第m大元素是多少 解法:这题较难的地方在于转化思维.如果去求所有区间的第k小,最坏复杂度是O(n*n)肯定超时. 这题正确的解 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 2017年10月WEB前端开发实习生面试题总结
从大一开始学习前端,今年大三,10月份开始投简历,陆续收到很多家公司的面试,目前为止的面试通过率是百分之百,总结下面试题. 不定期更新中... 百度第一次 一面 1.AJAX流程 2.promise简 ...
- 原生JavaScript实现的贪吃蛇
github代码地址:https://github.com/McRayFE/snake 涉及到的知识点: 键盘事件 setInterval()定时器 javascript中数组的使用 碰撞的检测 of ...
- Windows下Visual Studio2017之AI环境搭建
本博客主要包含以下3点: AI简介及本博客主要目的 环境介绍及安装原因 搭建环境及检验是否安装成功 离线模型的训练 时间分配: 时间 时长(分钟) 收集资料+写博客 6.12 11:28-12:2 ...
- Final发布文案+美工
团队名称:探路者 1蔺依铭:http://www.cnblogs.com/linym762/(组长) 2张恩聚:http://www.cnblogs.com/zej87/ 3米赫:http://www ...
- Scrum Meeting 10.28
今天大部分同学仍停留在学习阶段,进度快的同学已经在配置SQLserver. 成员 今日完成任务 明日计划 所用时间 徐越 配置SQLserver,试用java程序连接数据库 学习servlet,htt ...
- 实验五Java网络编程及安全
实验五 Java网络编程及安全 结对伙伴:20135231林涵锦(负责服务器方)http://www.cnblogs.com/20135213lhj/ 实验目的与要求: 1.掌握Java网络编程的方 ...
- java学习de路线建议
我想谈一谈我的一些关于网页学习的小感悟吧.之所以是写这个的原因完全是想告诉现在还处在网页学习的初始阶段的同学一些我学习走过的弯路,但我说的也仅是我个人的理解,毕竟我只能是JavaWeb开发的新手,所以 ...
- WebGL学习笔记二
前一章就是第二章主要学的是通过WebGL实现先是在webGL内赋值,但是不实用后来通过定义attribute和uniform存储限定符来将javascript中的数据传到webGL中,大致的流程是1. ...
- Leetcode题库——5.最长回文子串
@author: ZZQ @software: PyCharm @file: longestPalindrome.py @time: 2018/9/18 20:06 要求:给定一个字符串 s,找到 s ...
- Ubuntu下ssh连接在服务端显示图形界面
Ubuntu下ssh连接在服务端显示图形界面 step1 安装ssh服务 服务端安装运行ssh,在终端运行命令如下: sudo apt-get install openssh-server 在客户端安 ...