ACPC10G - A Knights’ Tale

no tags 

Imagine a chess board that extends indefinitely in both horizontal and vertical directions. N identical knights are placed on this board, each in a different square. N different squares are specially marked, which we will call the target squares, which could be different from where the knights are initially at. We would like you to determine the minimum number of knight-steps needed so that each of the target squares is occupied by one of the knights.

a

As illustrated in the figure, a knight moves using the normal ā€Lā€ move (1 square in one dimension and 2 squares in the other dimension.) For this problem, it is possible for more than one knight to occupy the same square while trying to reach its final destination as long as each knight ends up in a different target square.

Input

Your program will be tested on one or more test cases. Each test case is specified using 2N +1 lines.
The first line specifies (1 ā‰¤ N ā‰¤ 15) which is the number of knights (or targets.) The following N lines each specifies the position of a knight by specifying two integers representing the x and y location. The remaining N lines each specifies the position of a target square again by specifying two integers representing the x and y location. All coordinates are 32-bit signed integers.
The last case is followed by a line with a single zero.

Output

For each test case, print the following line:
k. m
Where k is the test case number (starting at one,) and m is the minimum number of moves.

Example

Input:
2
3 5
6 5
5 3
7 3
0
Output:
1. 3

hide comments
Fajrin Azis: 2011-08-14 11:04:35

AC when change all variable in process to long long. the constraint said it's fit in int but not the answer.

Mohamed Abd El Monem: 2011-03-31 17:28:59

Accepted, it seems SPOJ machine is not that good :)

Mohamed Abd El Monem: 2011-03-31 17:28:59

I wonder why I get TLE while all test cases run on my machine in less than 2 seconds.


Added by:Omar ElAzazy
Date:2010-11-30
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ACPC 2010