Broken Line 07
Time limit0.1sMemory limit512 MB
Construct a rectilinear broken line from the origin that passes through all given dots, minimizing the number of segments; this is an output-only optimization task.
- Level
Medium7 of 10
- Topics
- Sorting, Greedy, Implementation
- Solved
- No attempts yet
Problem
Azerbaijan is famous for its carpets. As a master carpet designer, you want to make a new design by drawing a broken line. A broken line is a sequence of line segments in a two-dimensional plane, defined by a sequence of points as follows. For each there is a segment connecting points and .
To make the new design, you have already marked dots in a two-dimensional plane. The coordinates of dot () are . No two dots have the same x or the same y coordinate.
You now want to find a sequence of points that defines a broken line which
- starts at (that is, and ),
- contains all of the dots (not necessarily as the endpoints of the segments), and
- consists solely of horizontal or vertical segments (two consecutive points defining the broken line have an equal x or y coordinate).
The broken line is allowed to intersect or overlap itself in any way. Formally, each point of the plane may belong to any number of segments of the broken line.
This is an output-only task with partial scoring. You are given input files specifying the locations of dots. For each input file, you should submit an output file describing a broken line with the required properties. For each output file that describes a valid broken line, your score depends on the number of segments in the broken line (see Scoring below).
Input
Each input file is in the following format:
- line :
- line (for ):
Output
Each output file must be in the following format:
- line :
- line (for ):
Note that the second line should contain and (i.e., the output should not contain and ). Each and should be an integer.
Constraints
- All values of and are integers.
- No two dots have the same or the same coordinate, i.e. and for .