2 solutions
-
0
#include<bits/stdc++.h> using namespace std; const int N=1000; char a[N][N]; int check[N][N]; int m[N][N];
int n; int dx[4]={0,-1,0,1}; int dy[4]={-1,0,1,0}; void dfs(int nx,int ny,int deep) { deep++; check[nx][ny]=1; m[deep][1]=nx+1; m[deep][2]=ny+1; if(nxn-1&&nyn-1){ for(int j=1;j<=deep;j++){ cout<<"("<<m[j][1]<<","<<m[j][2]<<")"; if(j!=deep){ cout<<"->"; } } } for(int i=0;i<4;i++){ int x=dx[i]+nx; int y=dy[i]+ny; if(check[x][y]0&&x>=0&&x<n&&y>=0&&y<n&&a[x][y]'0'){ dfs(x,y,deep); } } } int main() { int i,j,deep=0; cin>>n; for(i=0;i<n;i++){ for(j=0;j<n;j++){ cin>>a[i][j]; } } dfs(0,0,deep); return 0; }
Information
- ID
- 768
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 8
- Tags
- # Submissions
- 258
- Accepted
- 49
- Uploaded By