algorithm - Count number of lines that will be seen by pilot as intersecting in a 2d plane -
the question goes this:
there 2 parallel buildings on each side of street. n number of ropes attached 1 floor of 1 building floor of other building ((a[i],b[i])
, a[i]
floor in first building on ith
rope attached , b[i]
floor on other building) . helicopter approaching building. how many intersections of ropes able see?
you can imagine tunnel scene movie dark knight
when gcpd helicopter comes rescuing harvey dent
gets strangled ropes.
you can imagine intersections in 2-d plane.
in picture attached below pilot see 1 intersection.
approaches
- the 1 approach think of brute-force, compare each rope other ropes intersection. want better that.
- i thought of sorting ropes according points of contact on 1 of building couldn't work out.
notes
- no, it's not of running competitions.
- i want approach, not code.
thanks in advance.
put left end positions binary search tree (rb, avl), right end positions sorted array/list, set links corresponding tree nodes (right end of segment knows node left end of a).
walk through array every right end: rank r of left end node add (r-1) result remove left end node tree
explanation: segment intersect other segments, left end upper, , right end lower
Comments
Post a Comment