#P7449. [THUSC 2016] 星露谷物语

    ID: 8324 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2016提交答案Special Judge随机化构造THUSC

[THUSC 2016] 星露谷物语

Problem Description

Recently, Xiao Cong, in order to forget the noise of the city, came to Stardew Valley to start farming and make a fortune. However, because Xiao Cong spent all the money on gacha draws, there was not enough money to buy seeds. To collect enough money to raise pigs, Xiao Cong has to start a large-scale search for wild vegetables.

Stardew Valley is an infinite two-dimensional plane, and you can move freely on this plane. Xiao Cong may find wild vegetables on nn line segments on this plane, but these segments are directed. Xiao Cong must move along the direction of a segment in order to find wild vegetables. To find more wild vegetables, Xiao Cong wants to walk through all places where wild vegetables may appear in Stardew Valley. In other words, for each segment, Xiao Cong needs to traverse every point on that segment along its direction. Of course, Xiao Cong may choose to traverse a segment in multiple parts. More specifically, Xiao Cong may leave the segment at any position and enter the segment again at any position, as long as the union of the traveled paths covers this directed segment.

Xiao Cong wants to find a path as short as possible. This path should consist of mm line segments and cover the nn directed segments in Stardew Valley. Xiao Cong may choose any point in Stardew Valley as the starting point of the path, and it must also be the ending point, i.e. Xiao Cong must finally return to the starting position.

Now, Xiao Cong needs to write a Connect Four (Si Zi Qi) course assignment, and does not know how to plan the walking route to make the moving distance as short as possible, so this difficult task is handed to you, the smart one.

Note: If two segments partially overlap and have the same direction, then when you walk through the overlapping part, we consider that this part of both segments has been traversed.

Input Format

The first line contains an integer nn, representing the number of directed segments.

The next nn lines each contain four integers x1,y1,x2,y2x_1, y_1, x_2, y_2, meaning this segment is a directed segment from (x1,y1)(x_1, y_1) to (x2,y2)(x_2, y_2).

Output Format

The first line should contain an integer mm, representing the number of points in the polyline path traveled by Xiao Cong, and it must satisfy mmin(5n2,5×106)m\le\min(5n^2,5\times 10^6). Then output mm lines, listing the points on the path in order. Each line should contain two floating-point numbers x,yx, y describing the xx- and yy-coordinates of a point. Here, x,yx, y should be kept to no more than 55 digits after the decimal point.

3
0 0 0 100
0 100 100 100
100 100 0 0
4
0 0
0 100
100 100
0 0
3
0 0 0 100
1 51 1 49
0 100 0 0
5
0 0
0 100
1 51
1 49
0 100

Hint

This is an output-only problem. The input and checker will be provided in the attachments.

For each testdata, if your output format does not meet the requirements, or if the path you output does not traverse all the given nn directed segments, then this test point gets 00 points. Otherwise, we will compute the length dd of your path, and calculate your score using 1010 scoring parameters a1a2...a10a_1\ge a_2\ge...\ge a_{10}:

max{idai,1i10}\max\{i|d\le a_i,1\le i\le 10\}

The data guarantees that a1a_1 is large enough to ensure that a valid solution can get at least 11 point.

Sample Explanation

For sample 11, Xiao Cong moved a total distance of 200+1002200+100\sqrt2, which is also the optimal solution for this sample.

For sample 22, in this solution, Xiao Cong moved a total distance of 202+2402+2602202+\sqrt{2402}+\sqrt{2602}, but this is not the optimal solution for this testdata.

Translated by ChatGPT 5