Single Cut of Failure
Time limit6sMemory limit1024 MB
Wires cross a rectangle between boundary sides; find the fewest straight cuts connecting different sides that cross every wire, and output the lexicographically smallest such cut.
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Implementation, Array
- Solved
- No attempts yet
Problem
The Intrusion and Crime Prevention Company builds intrusion detection systems for homes and businesses. The International Collegiate Programming Contest, which happens to share the same initials, is thinking about hiring the company to secure the room that holds the problem set for next year's world finals.
The contest staff wants to stop the intrusion attempts of past years: rappelling down the outside of the building to reach a window, crawling through air ducts, impersonating a contest official, and the creative use of an attack submarine. For that reason the problems will sit in a room with a single door and no other exit.
The company proposes sensors on the four sides of the door. Pairs of sensors are joined by wires, and every wire runs in a straight line across the door. When somebody opens the door, each connected pair detects it and sounds an alarm.
The design has one flaw. An intruder can cut the wires before opening the door. A cut is a straight segment whose two ends lie on the boundary of the door, and the two ends have to lie on different sides of the door. A cut destroys every wire it crosses. To measure how safe the system is, find the smallest number of cuts that together cross all of the wires.
The door is the rectangle with corners , , and .

Figure 1 draws the wires of the two examples and, for each of them, a set of cuts of the smallest possible size. The drawn cuts are one correct answer, not the specific answer this problem asks for.
Input
The first line contains three integers , and : the number of wires () and the width and the height of the door ().
Each of the next lines contains four integers , , and (, ), describing a wire that runs from to . Both anchors of a wire lie on the boundary of the door and on two different sides of it. No anchor is a corner of the door, and all anchor locations are distinct.
Output
Print the smallest number of cuts on the first line. Then print the cuts, one per line, as four numbers meaning the cut from to . One cut or two cuts are always enough, so the first line is 1 or 2.
Several sets of cuts can share the smallest size, so print the one described here. Measure a point of the boundary by the distance you walk along the boundary to reach it, starting at the corner and going to , then to , then to , and back to . The whole boundary has length , and every wire anchor sits at an integer distance. Both ends of every cut you print sit at a half-integer distance, meaning a distance whose fractional part is exactly . Such a point is never a corner and never an anchor.
If a single cut crosses all of the wires, print 1 and then that cut. Write for the smaller and for the larger of the two distances of its ends. Among all cuts whose ends sit at half-integer distances, lie on two different sides and cross every wire, take the one with the smallest , and among those the one with the smallest . Print the end at distance first.
If no single cut crosses all of the wires, print 2 and then exactly these two cuts in this order: the cut from to , then the cut from to .
Print a coordinate as an integer when it is a whole number, and with exactly one digit after the decimal point otherwise.