루미 알고리즘

#1307플래티넘Amusement Park

PO 2012 온라인 예선코딩영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

Lisa is visiting an amusement park and has decided which of the N rides she wants to go on. She wants to go on each ride exactly once. For each ride, there are two equivalent facilities at different locations, i.e. 2N facilities in total. Given the positions for each facility, help Lisa plan which facility to pick for each ride and in what order she should visit them to minimize the total distance she must walk to go on all the rides.

She starts and should finish at the entrance at (0, 0).

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: An illustration of the first sample with the optimal solution.

Input

The first line contains the integer N (1 ≤ N ≤ 15), the number of rides Lisa wants to go on. This is followed by N lines, describing each ride. One line contains four integers: the x and y coordinates of the first facility and then the x and y coordinates of the second facility. The absolute value of each coordinate is less than a million.

No facility has a position coinciding with that of another or of the entrance.

Output

The first line of the output should contain a decimal number: the minimum distance Lisa must walk. Then print N lines, each with two integers, listing the facilities she should visit. The first integer on a line should be between 1 and N and denote the ride she goes to, while the second should be 1 or 2 and denote which of the two facilities she should choose.

If there are several paths that give the same distance, you can output any one of them.

The relative or absolute error may not exceed 10^-5.

Scoring

Your solution will be tested on a set of test case groups. To get the points for a group, you need to pass all the test cases in the group.

GroupPoint valueConstraints
120N ≤ 1
240N ≤ 5
340No additional constraints.

예제

예제 1

입력
3
3 5 1 -1
-2 0 0 4
4 4 0 6
출력
14.233345
2 2
1 1
3 1

출처 표기

출처: Programmeringsolympiaden 2012년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.