博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
B - K-th Number HDU - 6231
阅读量:4114 次
发布时间:2019-05-25

本文共 781 字,大约阅读时间需要 2 分钟。

K-th Number HDU - 6231 

题意:给你n个数字,把所有区间中第k大的数字放在一起构成一个新的数组,如果选取的区间长度小于k则忽略不计,输出新数组中第m大的数字

思路:这个题目可以通过二分来实现,通过二分答案的大小。我们使用取尺法对原数组进行处理,如果我们当前验证答案x是否满足要求,我们可以先选取大于等于x的k个数字,如果前面大于等于x的数字的个数为k,则后面的区间都可以满足条件,然后我们在对去区间的开头进行改变, 对满足条件的区间进行计数,如果满足条件的区间的个数大于等于m则我们可以需要让答案变得大一些,如果小于m我们可以让答案小一些。

#include
using namespace std;const int maxn=1e5+50;int a[maxn];int n,k;long long m;long long check(int x){ int ans=0; int st=1; int num=0; long long res=0; for(int i=1; i<=n; i++) { if(a[i]>=x) num++; if(num==k) { res+=n-i+1; while(a[st]
=m) { ans=mid; l=mid+1; } else { r=mid; } } printf("%d\n",ans); }}

 

转载地址:http://gbgsi.baihongyu.com/

你可能感兴趣的文章
使用TcpClient可避免HttpWebRequest的常见错误
查看>>
EntityFramework 学习之一 —— 模型概述与环境搭建 .
查看>>
C# 发HTTP请求
查看>>
启动 LocalDB 和连接到 LocalDB
查看>>
Palindrome Number --回文整数
查看>>
Reverse Integer--反转整数
查看>>
Container With Most Water --装最多水的容器(重)
查看>>
Longest Common Prefix -最长公共前缀
查看>>
Letter Combinations of a Phone Number
查看>>
Single Number II --出现一次的数(重)
查看>>
Valid Parentheses --括号匹配
查看>>
Remove Element--原地移除重复元素
查看>>
Remove Duplicates from Sorted Array--从有序数组中移除重复元素
查看>>
Count and Say
查看>>
Gas Station
查看>>
Palindrome Partitioning --回文切割 深搜(重重)
查看>>
Valid Palindrome 简单的回文判断
查看>>
Pascal's Triangle -- 生成杨辉三角
查看>>
Pascal's Triangle II 生成杨辉三角中的某行
查看>>
Minimum Depth of Binary Tree -- 二叉树的最小深度 DFS 加剪枝
查看>>