Va knights in Fen

Source: Internet
Author: User

The questions are as follows:

Problem d

Knights in Fen

Input:Standard Input

Output:Standard output

Time limit:10 seconds

 

There are black and white knightson a 5 by 5 chessboard. there are twelve of each color, and there is one squarethat is empty. at any time, a knight can move into an empty square as long asit moves like a knight in normal chess (what else did you have CT ?).

Given an initial position of the board, thequestion is: what is the minimum number of moves in which we can reach thefinal position which is:

Input

First line of the input file contains an integern (n <14) that indicates how many sets of inputs are there. The descriptionof each set is given below:

Each set consists of five lines; each linerepresents one row of a chessboard. the positions occupied by white knights aremarked by 0 and the positions occupied by black knights are marked by 1. thespace corresponds to the empty square on board.

There is no blank line between the two sets ofinput.

The first set of the sample input belowcorresponds to this Configuration:

Output

For each set your task is to find the minimumnumber of moves leading from the starting input configuration to the final one. If that number is bigger than 10, then output one line stating

Unsolvable in less than 11 move(s).

 

Otherwise output one linestating

SolvableinNMove (s ).

WhereN<= 10.

Theoutput for each set is produced in a single line as shown in the sample output.

Sample Input
2
01011
110 1
01110
01010
00100
10110
01 11
10111
01001
00000
Sample output
Unsolvable in less than 11 move(s).
Solvable in 7 move(s).


A simple DFS is used to simulate a Trojan and determine whether the target State is used to update the minimum value.

The AC code is as follows:


Va knights in Fen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.