Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll give the solution in general words without programming it.</p> <p>Let's denote segments as s<sub>1</sub>, s<sub>2</sub>, ..., s<sub>n</sub>. Their beginnings as b<sub>1</sub>, b<sub>2</sub>,... b<sub>n</sub>, and their ends as e<sub>1</sub>, e<sub>2</sub>,... e<sub>n</sub>.</p> <p>Sort segments by their beginnings, so b<sub>1</sub>&lt; b<sub>2</sub>&lt;...&lt; b<sub>n</sub>. It is enough to check them if the condition of no three segments covering a point holds. We will be doing so in the order from b<sub>1</sub> to b<sub>n</sub>. So, start with b<sub>1</sub>, move to the next point, and so on one by one, until at some point b<sub>i</sub> there are three segments covering it. These will be the segment s<sub>i</sub> and two others, let's say s<sub>j</sub> and s<sub>k</sub>. Of those three segments delete the one with the maximum end point, i.e. max{e<sub>i</sub>, e<sub>j</sub>, e<sub>k</sub>}. Move on to the beginning of the next segment (b<sub>i+1</sub>). When we reach b<sub>n</sub> the process is done. All the segments that are left constitute the largest subset of segments such that no three segments share a common point.</p> <p>Why this will be the maximal subset. Let's say our solution is S (the set of segments). Suppose there is an optimal solution S*. Again, sort the segments in S and S* by the coordinate of their beginnings. Now, we will be going through the segments in S and in S* and comparing their end points. By the construction of S for any k<sup>th</sup> segment in S its end coordinate is smaller than the end coordinate of k<sup>th</sup> segment in S* (e<sub>k</sub>&lt;=e<sub>k</sub><em>). Therefore, the number of segments in S is not less than in S</em> (moving in S* we're always outrunning S).</p> <p>If this is not convincing enough, try to think about a simpler problem at first, where no two segments can overlap. The solution is the same, but it's much more intuitive to see why it gives the right answer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload