F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Chess

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 179    Accepted Submission(s): 7


Problem Description
You are given a standard 8*8 chess board. There are only pawns and kings on the board. In each move, a king can move to any of its 8 neighboring cells. If you move a king into a cell occupied by a pawnn, the king will capture that pawn. You can never move a king outside the board or into a cell already occupied by another king.

Now the problem is, what is the minimal number of moves required for the kings to capture all the powns?
 

Input
There are multiple cases (no more than 100).

There are exactly 8 lines for each case, representing the chess board. Each line has 8 characters. The '.' character represents an empty cell, 'P' represents a cell occupied by a pawn, and 'K' represents a cell occupied by a king.

For each board, the number of kings and the number of pawn are between 1 and 10, both inclusive.

Each case is followed by an empty line.
 

Output
For each case, output the minimal number of moves required for the kings to capture all the powns.
 

Sample Input
.PPPPKP. ........ ........ ........ ........ ........ ........ ........ P......P ........ ........ ........ ...KK... ........ ........ P......P .....P.P ..K....P ....K... ..PP...P ...K..KK ........ K....... KP.K....
 

Sample Output
6 20 9
 

Author
hhanger@zju
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-08 05:54:46, Gzip enabled