Closest two points MEDIUM Structuri (BAC) 25 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

Consider the data type `Punct`, defined as follows: ``` struct Punct { int x, y; }; ``` where `x` and `y` are the integer coordinates of a point in the plane. Read from standard input a natural number `n` (`n >= 2`), followed by the coordinates of `n` points. Print the two points at the smallest Euclidean distance, then the square of that distance. Distinct points may share a coordinate; if multiple pairs achieve the same minimum distance, print the first one in lexicographic order by indices (smallest `i` first, then smallest `j`). The point with the smaller index is printed first.

Input format

Input input.txt

The first line contains `n`. The next `n` lines each contain the coordinates `x y` of one point, separated by a space. - `2 <= n <= 200` - `-1000 <= x, y <= 1000` - it is guaranteed that no two points are identical

Output format

Output output.txt

The first two lines contain the two points, in the format `x y`. The third line contains the square of the Euclidean distance between them.

Example

input
4
0 0
3 4
1 1
10 10
output
0 0
1 1
2

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more