Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
solutioni wanna solution for this problem from where i do get this. my problem is : Bob is a student of NIT Jalandhar.Like all other students he likes to solve puzzles.In one such popular puzzle there is board in which there are m*m boxes each assigned an a non zero integer except one box which is marked as 0 and is treated as vacant .Only the vertical and horizontal neighbors of vacant box can move towards it leaving their place as vacant.To solve this puzzle bob has to arrange the boxes in increasing order of their value with the vacant box(box marked as zero ) coming at the end(lower right corner of board).But like all other engineers bob is very lazy and wants to solve it in minimum number of steps. Input: The first line of input consists of an interger t representing number of test case. Second line of input will be an integer m representing the size of board (m*m) . Third line of input consists of m*m space separated integers in which only one is 0 (vacant box). Output: Each test case has single output printing the minimum number of moves of solve the puzzle. CONSTRAINTS are: 5<= t <= 50 2<= m <=100 Sample Input 5 2 4 0 3 1 3 9 8 5 2 0 4 10 12 17 5 9 58 38 0 37 2 1 67 23 12 40 7 23 79 29 123 72 99 6895 35 60 547 768 34 999 6 12 45 78 3 90 1 -5 7 234 10 -4 -9 0 3456 71 29 91 1991 2012 1854 785963 786 7798 652034 9635 2357 68520 143 1010109 -9 -789 568 -95231 34786 16795 5468 7 1234 2345 3456 4567 5678 6789 963 852 741 1023 2048 0 7596 3489 123896 751 1258 1987 2013 2144 76349 10587 3 100 2879 5624 3020 5468 8426 1397 7821 3697 200300 546 739146 1231 4564 789654 2356 -850 -7896543 2581 -321 54648 235647 987628 2136 101034 53 Output 5 12 66 118 185 Explaination Initial state final state 4 0(vacant) 1 3 3 1 4 0(vacant) if someone finds a solution please email me asap my id is: amanjain110893@gmail.com Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator