码迷,mamicode.com
首页 > 其他好文 > 详细

marzullo's algorithm

时间:2014-11-14 12:10:22      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:ar   os   sp   for   on   art   cti   bs   res   

given several intervals, how to find a interval which is a intersect of the most number of the given intervals?

Method:

Step1: Represent each returned interval in the following form [start, +1] , [end, -1]
Step2: You now have a list of tuples, the first element of which is a time. Sort these tuples by the time, irrespective of whatever is the second element. So you would have [t(i), val(i)], [t(i+1), val(i+1)], ... where val(i) = ±1. 
Step3: initialize two vars count = 0 and max =0
Step4: Now run through the sorted tuples and set count = count + val(i)
            Compare if count > max then 
                                set max = count
                                set answer = [t(i), t(i+1)]
Step5: Return answer

marzullo's algorithm

标签:ar   os   sp   for   on   art   cti   bs   res   

原文地址:http://www.cnblogs.com/miaoz/p/4096752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!