UVA Knights in FEN

题目如下:

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:

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.

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的代码如下:

时间: 2024-10-10 15:50:48

UVA Knights in FEN的相关文章

UVa 10422 - Knights in FEN

題目:如題目的圖示給你一個5*5的棋盤上面有12個黑騎士和12個白騎士和一個空格: 現在要你從一個給定狀態變成目標狀態,每一可以移動一個騎士(走日字,國際象棋): 問多少步能走到目標狀態,超過10步輸出超過10步走到. 目標狀態: 分析:搜索,狀態壓縮,哈希表.用一個25位的01串可以表示任意一種狀態(空格用0表示(也可用1),避免當做兩種狀態): 所以每個狀態可以用一個int類型的數據表示,然後計算出個狀態的到達關係,bfs即可. 搜索時使用hash函數壓縮數據(頭則內存不夠). 說明:大年三

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

UVA 1364 - Knights of the Round Table(双连通+二分图判定)

UVA 1364 - Knights of the Round Table 题目链接 题意:有n个圆桌骑士,知道一些骑士互相憎恨,现在要开圆桌会议,每次最少3个人,必须是奇数人数,并且互相憎恨的骑士不能在相邻,问有多少骑士是一次都无法参加的 思路:把每个骑士可以相邻的连边,然后做双连通分量,然后对于每个连通分量,利用二分图染色判定去判断是否是奇圈 代码: #include <cstdio> #include <cstring> #include <vector> #in

UVA 1364 - Knights of the Round Table (找双连通分量 + 二分图染色法判断)

都特么别说话,我先A了这道题! 卧槽啊.....! 题意来自 kuangbin: 亚瑟王要在圆桌上召开骑士会议,为了不引发骑士之间的冲突, 并且能够让会议的议题有令人满意的结果,每次开会前都必须对出席会议的骑士有如下要求: 1.  相互憎恨的两个骑士不能坐在直接相邻的2个位置: 2.  出席会议的骑士数必须是奇数,这是为了让投票表决议题时都能有结果. 注意:1.所给出的憎恨关系一定是双向的,不存在单向憎恨关系. 2.由于是圆桌会议,则每个出席的骑士身边必定刚好有2个骑士. 即每个骑士的座位两边都

UVA 11292 Dragon of Loowater(简单贪心)

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

uva 11292

A - Dragon of Loowater Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 11292 Appoint description:  System Crawler  (2014-11-26) Description Problem C: The Dragon of Loowater Once upon a time, in the K

UVA之11292 Dragon of Loowater

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

·UVa」 11292 - Dragon of Loowater( 贪心 )

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

UVA它11292 - Dragon of Loowater

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato