zoj 1047

#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;

char map[25][25];
bool vis[25][25];
int n, m, a, b;
int len;
int dir[4][2] = {-1,0, 0,1, 1,0, 0,-1};
int dir_x[4][2] = {-1,-1, -1,1, 1,1, 1,-1};
void init(int n, int m)
{
  memset(vis, false,sizeof(vis));
  memset(map,'.',sizeof(map));
  len = 0;
  char str[25];
  for(int i=1; i<=n; i++)
  {
    scanf("%s",str);
  for(int j=1; j<=m; j++)
   map[i][j] = str[j-1];
 }
}
void dfs(int x, int y)
{
    vis[x][y] = true;
    for(int i=0; i<4; i++)
    {
      int x0 = x+dir[i][0];
      int y0 = y+dir[i][1];
      if(!vis[x0][y0]&&map[x0][y0]=='X')
      dfs(x0,y0);
      else if(!vis[x0][y0]&&map[x0][y0]=='.')
        len++; //dfs(x,y,len+1); 
    }  
    for(int i=0; i<4; i++)
    {
     int x0 = x + dir_x[i][0];
     int y0 = y + dir_x[i][1];
      if(!vis[x0][y0]&&map[x0][y0]=='X')
      dfs(x0,y0);
    }
}

int main()
{
    
while(scanf("%d",&n)&&n)
{
  scanf("%d%d%d",&m, &a, &b);
  init(n,m);
   dfs(a,b);
  printf("%d\n",len); 
}
system("pause");
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值