| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
咋都喜欢用广搜,深搜不简单吗?附AC小代码In Reply To:BFS一次AC o(∩_∩)o 附代码 Posted by:lsz at 2011-05-05 16:31:20 #include<iostream>
#include<cstdlib>
using namespace std;
int perimeter;
char g[22][22];
void dfs(int x,int y,bool flag)
{
if(g[x][y]=='.'&&flag)perimeter++;
if(g[x][y]!='X')return;
g[x][y]=0;
for(int i=x-1;i<=x+1;i++)
for(int j=y-1;j<=y+1;j++)
dfs(i,j,(i-x+j-y)%2);
}
int main()
{
int i,j,r,c,x,y;
while(cin>>r>>c>>x>>y,r+c+x+y)
{
memset(g,'.',sizeof(g));
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
cin>>g[i][j];
perimeter=0;
dfs(x,y,false);
cout<<perimeter<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator