

1 #include <iostream>
2 using namespace std;
3
4 const int N = 25;
5 int mat[N][N];
6 bool mk[N][N];
7 int d[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
8 int ans;
9 int cnt;
10 int r, c, s, e;
11
12 bool check(int x, int y) {
13
14 if(x >= 1 && x <= r && y >= 1 && y <= c)
15 return true;
16 return false;
17 }
18
19 void dfs(int x, int y) {
20
21 if(mat[x][y] == 1 && !mk[x][y]) {
22 mk[x][y] = true;
23 if(mat[x + 1][y] == 0)ans++;
24 if(mat[x][y + 1] == 0)ans++;
25 if(mat[x - 1][y] == 0)ans++;
26 if(mat[x][y - 1] == 0)ans++;
27 for(int i = 0; i < 8; i++) {
28 if(check(x + d[i][0], y + d[i][1]))
29 dfs(x + d[i][0], y + d[i][1]);
30 }
31 }
32 }
33
34 int main() {
35
36 int i, j, k;
37
38 while(cin >> r >> c >> s >> e) {
39 if(!(r + c + s + e))break;
40 getchar();
41 for(i = 0; i <= r + 1; i++)
42 for(j = 0; j <= c + 1; j++) {
43 mat[i][j] = 0;
44 mk[i][j] = 0;
45 }
46 char ch;
47 for(i = 1; i <= r; i++) {
48 for(j = 1; j <= c; j++) {
49
50 ch = getchar();
51 if(ch == 'X')mat[i][j] = 1;
52 }
53 getchar();
54 }
55 ans = 0;
56 dfs(s, e);
57 cout << ans << endl;
58 }
59 return 0;
60 }
61
posted on 2009-12-24 12:43
gdut08 阅读(79)
评论(0) 编辑 收藏 引用