码迷,mamicode.com
首页 > 其他好文 > 详细

UVA Knights in FEN

时间:2014-09-07 13:36:25      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:acm   dfs   uva   brute force   implicit graph trave   

题目如下:

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 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:

bubuko.com,布布扣

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:

bubuko.com,布布扣

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.

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).


简单的dfs,模拟跳马,判断出是目标状态后更新最小值。

AC的代码如下:


UVA Knights in FEN

标签:acm   dfs   uva   brute force   implicit graph trave   

原文地址:http://blog.csdn.net/u013840081/article/details/39118335

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!