An open API service indexing awesome lists of open source software.

https://github.com/bapjiws/cover-segments-with-points

Nailing the planks with a minimal amount of nails
https://github.com/bapjiws/cover-segments-with-points

Last synced: 2 months ago
JSON representation

Nailing the planks with a minimal amount of nails

Awesome Lists containing this project

README

        

Given n segments, provide a minimal set of points such that each segment contains at least one of these points.
The first input line contains 1 ≤ n ≤ 100 segments.
Each of n successive input lines contains two numbers 0 ≤ lr ≤ 109 -- segment's endpoints.
The task is to output the optimal amount of m points and these m points themselves.
If there are several such points sets, output any of those.

Sample Input 1:

3

1 3

2 5

3 6

Sample Output 1:

1

3

Sample Input 2:

4

4 7

1 3

2 5

5 6

Sample Output 2:

2

3 6