Hasan and Points Pairing
Practice
4.2 (34 votes)
Basic programming
Medium
Ready
Problem
43% Success 1060 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Hasan is feeling bored since he has been studying for his physics exam all day, that's why he started to do random stuff, he drew 2*N points on piece of paper, coordinates of i-th point is (Xi, Yi) and now he is wondering how to connect the points with N segments of minimum possible sum of lengths such that:

  • No two segments intersect.
  • And each point is an endpoint of exactly one segment .

(Yes, studying for exams made Hasan bored enough to wonder about weird questions) Help Hasan by answering his question so that he can continue to study for his exam.

Input format:

First line contain one integer N.
Next 2*N lines contains two integers each, i-th line contains coordinates of i-th point Xi and Yi.

Output format:

Output one number, the minimum sum of lengths of non-intersecting segments rounded to exactly 6 digits after floating point.

Constraints:

  • 1<= N <= 8
  • 0 <= Xi, Yi <= 1,000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
11 votes
Tags:
AlgorithmsApprovedCompletedMediumOpen
Points:30
5 votes
Tags:
AlgorithmsDynamic Programmingalgorithmsapproveddynamic programmingmediumnumber theoryreadyrecruitsieve
Points:30
2 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingFenwick TreeMediumSegment TreesSorting