30分求调
查看原帖
30分求调
1655190
Zjb0406楼主2025/7/26 23:27
#include<bits/stdc++.h>      
using namespace std;   
int n,m,flag=1;
char ch;
bool used[105][105];
int a_x[4] = {0,-1,0,1};
int b_y[4] = {1,0,-1,0};
void dfs(int xx,int yy){
	if(flag==0){
		return;
	}
	used[xx][yy] = true;
	if(xx==n&yy==m){ 
		flag=0;
		return;
	}
    for(int i=0;i<4;i++){
        int x = xx+a_x[i];
        int y = yy+b_y[i];
        if(x>=1&&x<=n&&y>=1&&y<=m&&!used[x][y]){
            cout<<x<<" "<<y<<endl;
        	dfs(x,y);
        }
    }	
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>ch;
            used[i][j] = ch=='.'?false:true;
		}
	}
    cout<<1<<" "<<1<<endl;
	dfs(1,1);
    return 0;  
}
2025/7/26 23:27
加载中...