eolymp
bolt
Try our new interface for solving problems
Məsələlər

Drawing Problem

Drawing Problem

Recently Andy has found an old book in the attic. The book from the end of the XIX-th century contains a lot of various puzzles. One puzzle impressed Andy very much --- the complicated figure is drawn on the page and the task is to draw it in one stroke, never lifting the pen off the paper and never drawing the same non-zero part twice. To make the problem harder, the additional quest is to do it drawing the minimal number of segments. Having spent several hours on the problem, Andy asked you to write the program that would do it for him. \InputFile Input file contains the figure to be drawn as the set of segments. First the number of segments is specified. It is followed by segments descriptions. Each segment is described with coordinates of its endpoints. All segments are parallel to the sides of the page, that are aligned with coordinate axis. The number of segments does not exceed one hundred, all coordinates are integer and no not exceed one million by their absolute value, no two segments have a part of non-zero length in common. \OutputFile If it is impossible to fulfil the task, output zero on the first line of the output file. In the other case output the minimal number of segments to draw, followed by the segments themselves. Remember that it must be possible to draw segments continuously in order you list them, neither lifting the pen off the paper, nor drawing any non-zero segment twice. Endpoints of each segment must be listed in such an order, that it is drawn from the first endpoint to the second one.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
12
-2 2 -2 3
-1 1 -1 4
0 0 0 5
1 0 1 5
2 1 2 4
3 2 3 3
0 0 1 0
-1 1 2 1
-2 2 3 2
-2 3 3 3
-1 4 2 4
0 5 1 5
Çıxış verilənləri #1
16
-2 2 -2 3
-2 3 -1 3
-1 3 -1 4
-1 4 0 4
0 4 0 5
0 5 1 5
1 5 1 0
1 0 0 0
0 0 0 4
0 4 2 4
2 4 2 1
2 1 -1 1
-1 1 -1 3
-1 3 3 3
3 3 3 2
3 2 -2 2
Mənbə Russian Teams Training Sessions in Petrozavodsk, Summer 2004, Andrew Stankevich Contest 8, Thursday, August 26, 2004