English 中文(简体)
如何找到所有间隔的最高点?
原标题:How to find max score for all intervals?

我在开展一个项目时就遇到了这一问题,并想知道解决这一问题的最佳方式:

Saye 我的分数间隔如下,我想在间隔期间找到最高分数。

3-8 20
4-10 40
8-12 10
9-13 20

其结果应为40+10+5 = 70

3-8 and 4-10 overlap at 4-8 with a total score of 40+20 = 60 4-10, 8-12, and 9-13, all overlap at 9-10 with a score of 40+10+20 = 70

Obviously we have other overlaps like every interval by itself, or 8-12 and 9-13 excluding 4-10, but those dont yield a maximum. I also ideally would want to return the overlap that yielded the max amount, which in this case would be the 9-10 interval, which corresponds to the interval at which all 3 intervals that yielded the max score amount share.

解决这一问题将是一个好的算法?

我最初的想法是按起点进行分类,然后检查以前的间隔是否重叠(这足够容易),我很快提出的问题是,我们有:

3-9 20
4-10 40
8-12 10
9-13 30

我们感到振奋的是,我们认为3-9重叠,4-10重叠,有60,3-9,4-10,8-12重叠,有70。 然而,当我们发现9-13时,我们需要稍加停止考虑3-9,现在看看看看4-10、8-12、9-13重叠、80和9-10重叠。 是否可能有滑坡窗口?

问题回答

将起点与正面分数和负分点挂钩。 将所有点放在一起,并跟踪 cur; 最大累积总和; 与最高数额相关的开端/晚期。

如果你想要获得一点高分,就会打破有利于正面的纽带,否则会打破有利于消极因素的联系。

E.g.

3-8 20
4-10 40
8-12 10
9-13 20

Time  Score  Cur   Max
 3    +20    20    20
 4    +40    60    60
 8    +10    70    70  # Tie broken in favor of positive
 8    -20    50    70
 9    +20    70    70
10    -40    30    70
12    -10    20    70
13    -20     0    70




相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签