← 返回 waymo 的题目列表Minimum travel path for a pen-plotter to draw given strokes
类型:online_judge
Problem: Minimum travel path for a pen-plotter to draw given strokes
You are implementing a pen-plotter robot that moves a pen on paper to draw a figure. You are given n strokes, each stroke being a straight line segment with two endpoints. The robot must draw every stroke.
The pen has two movement modes:
Pen-down (drawing): movement along a stroke leaves ink and contributes distance.
Pen-up (travel): movement without drawing still costs distance.
You may choose:
The order in which strokes are drawn.
The direction of each stroke (you may draw a stroke from either endpoint).
Your goal is to minimize the total traveled distance (pen-down drawing distance + pen-up travel distance).
Input
Integer n (number of strokes)
Next n lines: x1 y1 x2 y2 describing the endpoints of each stroke
The robot starts at (0,0) with pen up.
Output
Output the minimum possible total travel distance.
Constraints
1 <= n <= 15
Coordinates are integers, assume range [-1e4, 1e4]
Use Euclidean distance.
Example
Input:
2
0 0 1 0
2 0 3 0
Output:
3.0
Example
Input
1
0 0 3 4
Output
5.0000000000