其他分享
首页 > 其他分享> > 2020-03-04

2020-03-04

作者:互联网

我想请教一下我写的这个DFS一直显示exe已停止工作,求解答

#include<bits/stdc++.h>
#define check(x,y) (x>=0&&x<Wx&&y>=0&&y<Hy)
using namespace std;
char room[21][21];
struct node{int x,y;};
int dir[4][2]={{0,-1},{1,0},{0,1},{-1,-0}}; 
int Wx,Hy,num=0;
void DFS(int dx,int dy){	
room[dx][dy]=='#';   
 num++;    	
 for(int i=0;i<4;i++){    		i
 nt newx=dx+dir[i][0];    		
 int newy=dy+dir[i][1];    		
 if(check(newx,newy)&&room[newx][newy]=='.'){    			DFS(newx,newy);    		    		}    	}
 retuen;}
 int main(){
 int x,y,dx,dy;
 while(cin>>Wx>>Hy){    
  if(Wx==0&&Hy==0)     break;       
  for(x=0;x<Wx;x++){        
   for(y=0;y<Hy;y++){          
     cin>>room[x][y];              i
     f(room[x][y]=='@'){                
       dx=x;                
         dy=y;              }         }       }      
               DFS(dx,dy);    
                  cout<<num<<endl;}
                  return 0;}

标签:03,Hy,&&,04,DFS,2020,dx,dy,Wx
来源: https://blog.csdn.net/qq_46009046/article/details/104651392