Devu and his mouse Jerry
All submissions for this problem are available.
Read problems statements in Mandarin Chinese , Russian and Vietnamese
Devu loves to play with his dear mouse Jerry. One day they play a game on 2 dimensional grid of dimensions n * n (n ≥ 2). Jerry is currently at coordinates (sx, sy) and wants to move to location (ex, ey) where cheese is placed by Devu. Also Devu is very cunning and has placed a bomb at location (bx, by). All these three locations are distinct.
In a single move, Jerry can go either up, down, left or right in the grid such that it never goes out of the grid. Also, it has to avoid the bomb. Find out minimum number of moves Jerry needs. It is guaranteed that it is always possible to do so.
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows."
- The first line of each test case contains seven space separated integers n, sx, sy , ex, ey, bx, by.
- For each test case, output a single line containing an integer corresponding to minimum number of moves Jerry needs.
- 1 ≤ T ≤ 1000
- 2 ≤ n ≤ 20
- 1 ≤ sx, sy , ex, ey, bx, by ≤ n
- No two or more poitns in the three points are same.
Input: 2 2 1 1 2 2 1 2 3 1 1 1 3 1 2 Output: 2 4
Example case 1. ...Jerry will move directly (1, 1) to (2, 1) and then to (2, 2) in total 2 moves.
Example case 2. ...
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.