为啥WA5点
查看原帖
为啥WA5点
1032333
Barryb楼主2024/4/25 21:34
#include<bits/stdc++.h>
using namespace std;
int n, m, anx, ansy, cnt;
string s[505];
char last;
void dfs(int x,int y)
{
	if(x<1||x>n||y<1||y>m||cnt>n*m) 
	{
		if(last=='U') x++;
		else if(last=='R') y--;
		else if(last=='L') y++;
		else x--; 
		if(x==1&&y==1) 
		{
			anx=-1,ansy=-1;
			return ; 
		}
		anx=x,ansy=y;
		return ;
	}
	last=s[x][y-1];
	if(s[x][y-1]=='U') x--;
	else if(s[x][y-1]=='R') y++;
	else if(s[x][y-1]=='L') y--;
	else x++;
	cnt++;
	dfs(x,y);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
	}
	dfs(1,1);
	if(anx==-1) cout<<-1<<endl;
	else cout<<anx<<" "<<ansy<<endl;
	return 0;
}
2024/4/25 21:34
加载中...