RE求调qwq
查看原帖
RE求调qwq
551630
Lemon_zqp楼主2024/1/14 12:09
#include<bits/stdc++.h>
using namespace std;

bool mp[105][105];
int n, m;
int dx[5] = {-1, 1, 0, 0};
int dy[5] = {0, 0, -1, 1};

bool dfs(int x, int y){
	if(x == n && y == m){
		return true;
	}
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && mp[nx][ny]){
			mp[nx][ny] = false;
			cout << nx << " " << ny << endl;
			dfs(nx, ny);
			mp[nx][ny] = true;
		}
	}
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			char a;
			cin >> a;
			if(a == '.'){
				mp[i][j] = true;
			}
			else{
				mp[i][j] = false;
			}
		}
	}
	if(dfs(1, 1)){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	return 0;
}


2024/1/14 12:09
加载中...