17. Closest Two Points, Classes, Constructors, Access Modifiers, Methods
Здравейте, може ли да ми помогнете, тъй като имам някакъв бъг в кода и не мога да го открия.
Условие:
1.Closest Two Points
Write a program to read n points and find the closest two of them.
Input
The input holds the number of points n and n lines, each holding a point {X and Y coordinate}.
Output
- The output holds the shortest distance and the closest two points.
- If several pairs of points are equally close, print the first of them (from top to bottom).
Examples
Input |
Output |
Visualization |
Comments |
4 3 4 6 8 2 5 -1 3 |
1.414 (3, 4) (2, 5) |
The closest two points are {3, 4} and {2, 5} at distance 1.4142135623731 ≈ 1.414. |
|
3 12 -30 6 18 6 18 |
0.000 (6, 18) (6, 18) |
Two of the points have the same coordinates {6, 18}, so the distance between them is 0. |
|
3 1 1 2 2 3 3 |
1.414 (1, 1) (2, 2) |
The pairs of points {{1, 1}, {2, 2}} and {{2,2}, {3,3}} stay at the same distance, but the first pair is {{1, 1}, {2, 2}}. The distance between them is 1.4142135623731 ≈ 1.414. |