到底哪里错误?
查看原帖
到底哪里错误?
591979
ShenRuochen楼主2022/8/28 23:44

RT,调了将近1小时了,还是WA+RE

#include <bits/stdc++.h>
using namespace std;
int n,m,vis[51][51][51][51];
int dx[5]={0,1,-1,0,0};//Right Left Down Up
int dy[5]={0,0,0,1,-1};
char ch[51][51];
bool dfs(int y,int x,int me,int d)
{
	y=(y+n)%n;
	x=(x+m)%m;
	if(vis[y][x][me][d])
		return 0;
	vis[y][x][me][d]=1;
	if(ch[y][x]=='<')
		d=2;
	else if(ch[y][x]=='>')
		d=1;
	else if(ch[y][x]=='^')
		d=4;
	else if(ch[y][x]=='v')
		d=3;
	else if(ch[y][x]=='_')
	{
		if(!me)
			d=1;
		else
			d=2;
	}
	else if(ch[y][x]=='|')
	{
		if(!me)
			d=3;
		else
			d=4;
	}
	else if(ch[y][x]=='?')
		for(int i=1;i<4;i++)
			if(dfs(y+dy[i],x+dx[i],me,i))
				return 1;
	else if(ch[y][x]=='@')
		return 1;
	else if(ch[y][x]=='+')
		me=(me+1)%16;
	else if(ch[y][x]=='-')
		me=(me+15)%16;
	else
		me=ch[y][x]-'0';
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
			cin>>ch[i];
	if(dfs(0,0,0,1))
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl; 
	return 0;
}
2022/8/28 23:44
加载中...