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

Where is the King

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 478    Accepted Submission(s): 187


Problem Description
¡¡¡¡There is a King placed on an N * N chessboard. In each second, Bob must move the King to the next cell in one of the eight directions, but he can not move the King to the outside of the chessboard, and can not move the King to a damaged cell. Note: If and only if there is not any next cell that he can place the King on in the eight directions, the King will stay in the same cell.
Now your task is to calculate that, after T seconds, the number of the cells that the King could be on.
 

Input
¡¡¡¡There is an integer C (1 <= C <= 500) in the first line, indicates there are C test cases in total.
¡¡¡¡For each test case, there are four integers N (2 <= N <= 100), T (1 <= T <= 1000000000), X (1 <= X <= N), Y (1 <= Y <= N). N and T have the same meaning as above, (X, Y) indicates the King¡¯s initial location. Then there are N lines. In each line, there is a string with N characters include ¡°#¡± and ¡°.¡±, which indicates the states of the cells in this row. ¡°#¡± means this cell is damaged, and ¡°.¡± means this cell is ordinary. You can assume (X, Y) is an ordinary cell.
¡¡¡¡For the coordinate (x, y), it stands for the cell in row x and column y. The coordinate of the top-left cell is (1, 1), and the coordinate of the bottom-right cell is (N, N).
 

Output
¡¡¡¡For each test case, you should output the correct answer of the above task in one line.
 

Sample Input
3 3 1 3 3 ... ... ... 3 2 3 3 ... ..# .#. 3 4 1 3 .#. .## ...
 

Sample Output
3 6 1
 

Hint

For Sample 1, the blue cells in the left picture of the Figure 1 show the cells that the King could be on after 1 second.
¡¡¡¡For Sample 2, the blue cells in the right picture of the Figure 1 show the cells that the King could be on after 2 seconds.
The red cells stand for the damaged cells, and the yellow cells shows other ordinary cells.

 

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-11-22 21:12:19, Gzip enabled