KNIGHT - Martian Chess
You are the chess champion of your country . One night before the world finals , when you were sleeping , Martians zap to you to Mars to teach them chess . You see that the chess Martians play is nearly same except they don't have a Knight . And Martians want you to write a program to teach them about Knight. The knight has an unusual style of "jumping" around the board. One move consists of traveling two squares in one of the four cardinal directions, followed by one square perpendicular to the original direction. For example, if a knight is on (0, 0), it may move to (2, 1), (2, -1), (1, 2), (1, -2), (-2, 1), (-2, -1), (-1, 2), or (-1, -2). In addition, if a piece is on any of those locations, it is threatened by the knight on (0, 0). You will be given a number and set of positions on a board (not necessarily 8x8). Calculate and return positions which are threatened by every knight in the input. The output should be sorted in increasing order with respect to x position and then by y position. You need to write this code quickly, else you will miss tomorrow's world finals.
Input
Number N, followed by N positions of the knights in All the positions threatened by input positions in N will between 1 and 8Output
Constraints
Each co-ordinate is between -10000 and 10000 , inclusive.
Each element will be unique.
Example
Input:
1
0,0
Output:
-2,-1 -2,1 -1,-2 -1,2 1,-2 1,2 2,-1 2,1
Added by: | Maruti Borker |
Date: | 2008-02-09 |
Time limit: | 0.100s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | C CPP JAVA TEXT |