1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream> #include <cstdio> #include <cstring> using namespace std;
char map[21][21]; int mapnum[21][21]; int dir[16]={1,1,1,0,1,-1,0,-1,-1,-1,-1,0,-1,1,0,1}; int r,c,a,b,sum; void search(int a,int b) { int x,y; mapnum[a][b]=1; for(int i=0;i<16;i+=2) { x=a+dir[i]; y=b+dir[i+1]; if(x>=1&&x;<=r&&y;>=1&&y;<=c) { if(map[x][y]=='X'&&mapnum;[x][y]==0) search(x,y); else if(map[x][y]=='.'&&(x==a||y==b)) sum++; } else if(x==a||y==b) sum++; } } int main() { int x,y; while(cin>>r>>c>>x>>y&&r;) { memset(mapnum,0,sizeof(mapnum)); for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) cin>>map[i][j]; sum=0; search(x,y); cout<<sum<<endl; } }
|