标签:acm dfs uva brute force implicit graph trave
题目如下:
Problem D
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 expect?).
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
Solvablein nmove(s).
where n <= 10.
Theoutput for each set is produced in a single line as shown in the sample output.
2
01011
110 1
01110
01010
00100
10110
01 11
10111
01001
00000
Unsolvable in less than 11 move(s).
Solvable in 7 move(s).
简单的dfs,模拟跳马,判断出是目标状态后更新最小值。
AC的代码如下:
标签:acm dfs uva brute force implicit graph trave
原文地址:http://blog.csdn.net/u013840081/article/details/39118335