CSHOWF1 - Sir and Chess1
After a lot of practice throughout the day, Sir jadeja is tired now and he is going to play chess for refreshment. While playing chess, a problem came into his mind. He wants to know the total numbers of ways a king can be placed on the chess board so that it cannot be attacked by the two knights already placed on the board. Help Sir jadeja in solving the problem.
Input
The first line of the input contains integer T denoting the number of test cases. First line of each test case contains an integer N denoting the size of board. Second line contains four integers x1, y1, x2, y2 separated by spaces denoting the position of the two knights. x1, y1 is the position of the first knight and x2, y2 is the position of the second.
Chess board will be of size N x N. Assume top left position as 1, 1 and bottom right position as N, N. A position x, y denotes block on xth row and yth column.
Output
For each test case print the answer of the problem.
Constraints
1 <= T <= 100
6 <= N <= 10000
Note
- There will be only 3 pieces on the board - 2 knights and 1 king.
- The king cannot occupy the positions already occupied by the knights.
Example
Input: 3 8 3 3 5 6 6 1 1 6 6 6 1 1 5 3 Output: 46 30 27
hide comments
nadstratosfer:
2018-07-22 16:36:38
Useful intro for beginners to the non-attacking chess pieces category. |
|
Mitch Schwartz:
2013-11-01 18:48:08
Moved to tutorial. |
|
Raushan Kumar:
2013-11-01 12:32:31
easy one got accepted in one go Last edit: 2013-11-01 12:33:35 |
Added by: | Aradhya |
Date: | 2013-10-25 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | CodeShow IIIT Allahabad |