Advertisement
MaskerQwQ

P1793

Mar 9th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool v[8][8];
  6. char maze[8][8];
  7. int dx[4]={0,0,-1,1};
  8. int dy[4]={-1,1,0,0};
  9. int nx,ny;
  10.  
  11. void dfs(int a,int b){
  12.     if(a==7&&b==7){
  13.         for(int i=0;i<=7;i++){
  14.             for(int j=0;j<=7;j++){
  15.                 if(v[i][j]!=0){
  16.                     cout<<" ";
  17.                 }else{
  18.                     cout<<maze[i][j];
  19.                 }
  20.             }
  21.             cout<<endl;
  22.         }
  23.     }else{
  24.         for(int i=0;i<4;i++){
  25.             nx=a+dx[i];
  26.             ny=b+dy[i];
  27.             if(nx>=0&&nx<=7&&ny>=0&&ny<=7&&maze[nx][ny]=='O'&&!v[nx][ny]){
  28.                 v[nx][ny]=1;
  29.                 dfs(nx,ny);
  30.                 v[nx][ny]=1;
  31.             }else{
  32.                
  33.             }
  34.         }
  35.     }
  36. }
  37. int main(){
  38.     for(int i=0;i<=7;i++){
  39.         for(int j=0;j<=7;j++){
  40.             cin>>maze[i][j];
  41.         }
  42.     }
  43.     memset(v,false,sizeof(v));
  44.     v[0][0]=1;
  45.     dfs(0,0);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement