RE#10 输出全对,最后return 3221226356
查看原帖
RE#10 输出全对,最后return 3221226356
777911
hansen121楼主2024/1/26 20:27
#include <bits/stdc++.h>
using namespace std;
char a[125][125];
int dx[7]={0,1,0,-1,0};
int dy[7]={0,0,1,0,-1};
int n,m;
struct o//坐标类型 
{
	int x,y; 
};
struct s//路径类型 
{
	int x,y,st;
};
bool visit[701][701];
stack<o>q;
stack<o>ss;
int f=0;
void dfs(int x,int y)
{
	if (x==n&&y==m)
	{
		cout<<1<<" "<<1<<endl;
		while(!q.empty())
		{
			o t=q.top();
			q.pop();
			ss.push(t);
		}
		while(!ss.empty())
		{
			cout<<ss.top().x<<" "<<ss.top().y<<endl;
			ss.pop();
		}
		f=1;
	}
	if (f==1) return;
	visit[x][y]=true;
	for(int i=1;i<=4;i++)
	{
		int xx=x+dx[i];
		int yy=y+dy[i];
		if (a[xx][yy]=='*') continue;
		if (xx>n||yy>m||xx<1||yy<1||visit[xx][yy]==true) continue;
		q.push((o){xx,yy});
		dfs(xx,yy);
		q.pop();
		if (f==1) return;
	}
	if (f==1) return;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
		}
	}
	dfs(1,1);
	if (f==0) cout<<"";
	return 0;
} 
2024/1/26 20:27
加载中...