问题描述
我有很多正整数的区间,每个区间都有一个分数。我想找到一组没有任何重叠的区间。我有选择重叠区间的这些条件:
1.如果两个区间重叠,则选择一个高分区间。
2.如果两个分数相同,则选择第一个间隔。
例如,如果我们有这些间隔(顺序很重要):
I have many intervals of positive integer numbers that each of them has a score. I want to find a set of intervals that do not have any overlapping. I have these conditions for selecting overlapped intervals:
1.if two interval overlap then select an interval with high score.
2.if both have same score, select the first interval.
for example if we have these intervals(order is important):
[0,3],[5,9],[1,4],[12,15],[17,20],[13,16],[16,16],[22,24]
score={1,5,0,12,17,13,20,22}
结果间隔为:
The result intervals are:
[0,3],[5,9],[16,16],[22,24]
我必须按如下方式定义间隔:
I have to define intervals as follows:
int[] intervalStart={0,5,1,12,17,13,16,22};
int[] intervalEnd={3,9,4,15,20,16,16,24};
int[] scores={1,5,0,12,17,13,20,22};
和例外结果是一个由选定的区间索引组成的数组:
and excepted result is an array that consist of selected interval indexes:
int[] result={0,1,6,7};
如何做到这一点并找到这个集合?
推荐答案
这篇关于如何找到没有任何重叠的间隔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!