听取WA声一片!
查看原帖
听取WA声一片!
1457886
poordoor楼主2024/11/3 23:39
#include<bits/stdc++.h>
using namespace std;
bool a[102][102],w=false;
int sx,sy,fx,fy;
	int n,m;
int z[4]={
0,1,0,-1
},
c[4]={
1,0,-1,0
};

void fun(int x,int y){
	a[x][y]=false;
	if(x==n&&y==m){
		w=true;
		cout<<"YES";
		return;
	}
	int tx,ty;
	for(int i=0;i<=3;i++){
		tx=x+z[i];
		ty=y+c[i];
	if(tx<=n&&tx>=1&&ty<=m&&ty>=1&&a[tx][ty])fun(tx,ty);
}
}
int main(){
	char k;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>k;
		if(k=='#')a[i][j]=false;
		else if(k=='.')a[i][j]=true;
		}
	}
	fun(1,1);
	if(w==false)cout<<"NO";
	return 0;
} 

听取WA声一片。

2024/11/3 23:39
加载中...