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.

enter image description here

approaches

  1. the 1 approach think of brute-force, compare each rope other ropes intersection. want better that.
  2. i thought of sorting ropes according points of contact on 1 of building couldn't work out.

notes

  1. no, it's not of running competitions.
  2. 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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -