#FW0000097. Bạn có thể thắng không? (Can U Win?)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bạn có thể thắng không? (Can U Win?)
Can U Win?
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You control a chess knight k on an board with enemy pawns P, empty squares ., and forbidden cells #. The knight moves in L-shapes, with offsets or . It may leap over occupied cells but may not land on a forbidden square. Determine whether the knight can capture all P pawns in at most moves.
Input
First an integer , the maximum number of moves. Exactly 8 board rows follow, each containing 8 characters from {k,P,.,#}. There is exactly one k piece; is the number of P pawns.
Output
Print exactly Yes if every pawn can be captured within at most moves; otherwise print No.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . All input-format and graph conditions above apply.
Examples
Input
1
k.......
..P.....
........
........
........
........
........
........
Output
Yes
Explanation
Knight k starts at row 1, column 1; pawn P is at row 2, column 3. Offset is a legal knight move. Since , the answer is Yes.