1216:红与黑
作者:互联网
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 5 const int N=25; 6 int w,h,ans,a[N][N],che[8]; 7 bool check(int x,int y){ 8 if(x>=0&&x<h&&y>=0&&y<w&&!a[x][y]) 9 return 1; 10 return 0; 11 } 12 void dfs(int x,int y){ 13 ans+=a[x][y]=1; 14 for(int i=0;i<4;i++){ 15 if(check(x+che[i],y+che[i+4])){ 16 dfs(x+che[i],y+che[i+4]); 17 } 18 } 19 } 20 int main(){ 21 int x,y; 22 char c; 23 che[0]=-1,che[1]=1,che[6]=-1,che[7]=1; 24 cin>>w>>h; 25 while(w||h){ 26 //初始化数据 27 ans=0; 28 memset(a,0,sizeof(a)); 29 for(int i=0;i<h;i++) 30 for(int j=0;j<w;j++){ 31 cin>>c; 32 if(c=='#')a[i][j]=-1; 33 if(c=='@') 34 x=i,y=j; 35 } 36 dfs(x,y); 37 cout<<ans<<endl; 38 cin>>w>>h; 39 } 40 return 0; 41 }
标签:25,1216,int,红与黑,&&,ans,include 来源: https://www.cnblogs.com/sxrekord/p/red_and_black.html