Redian新闻
>
dynamically找最近m个数里最大的那个
avatar
dynamically找最近m个数里最大的那个# JobHunting - 待字闺中
r*k
1
咋做?
实际就是搜索引擎最近30分钟内频率最高的query吧?
我想到一个循环数组记堆内index
然后用堆存数值
每来一个新数,把新数放到要扔掉的老数的位置
然后update堆
不过index会变化比较多
avatar
l*a
2
一个queue,keep the latest m , the head keep the oldest
another queue, keep the biggest among recent m
when u have a new number,remove all those less than it and then add it to
the tail of the queue.
when u remove a number from the first queue, once it is the head of 2nd
queue,remove both of them

【在 r*******k 的大作中提到】
: 咋做?
: 实际就是搜索引擎最近30分钟内频率最高的query吧?
: 我想到一个循环数组记堆内index
: 然后用堆存数值
: 每来一个新数,把新数放到要扔掉的老数的位置
: 然后update堆
: 不过index会变化比较多

avatar
y*n
3
another queue, keep the biggest among recent m,
这个Queue 要多大。。

【在 l*****a 的大作中提到】
: 一个queue,keep the latest m , the head keep the oldest
: another queue, keep the biggest among recent m
: when u have a new number,remove all those less than it and then add it to
: the tail of the queue.
: when u remove a number from the first queue, once it is the head of 2nd
: queue,remove both of them

avatar
l*a
4
at most m

【在 y***n 的大作中提到】
: another queue, keep the biggest among recent m,
: 这个Queue 要多大。。

avatar
j*3
5
没看懂,怎么个意思?
avatar
Z*4
6
楼主题目再说详细点?
avatar
r*k
7
有点意思,像是对stack实现min的思路

【在 l*****a 的大作中提到】
: 一个queue,keep the latest m , the head keep the oldest
: another queue, keep the biggest among recent m
: when u have a new number,remove all those less than it and then add it to
: the tail of the queue.
: when u remove a number from the first queue, once it is the head of 2nd
: queue,remove both of them

avatar
X*4
8
sliding window?
avatar
r*k
9
是啊
用一个最大堆,
放入最初的k个数,堆顶的元素即是最大值。
然后把下一个元素放入,更新堆。
如果堆顶元素不在index范围内,弹出,直到符合,输出最大值。
O(nlogk)

【在 X*4 的大作中提到】
: sliding window?
avatar
X*4
10
sliding window 有o(n) algorithm + o(k) space算法吧

【在 r*******k 的大作中提到】
: 是啊
: 用一个最大堆,
: 放入最初的k个数,堆顶的元素即是最大值。
: 然后把下一个元素放入,更新堆。
: 如果堆顶元素不在index范围内,弹出,直到符合,输出最大值。
: O(nlogk)

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。