help0分WA
查看原帖
help0分WA
529038
Butterfly__qwq楼主2022/2/11 16:21
#include<bits/stdc++.h>
using namespace std;
int chs[1001][1001],vis[1001][1001];
const int dx[]={-1,1,0,0},dy[]={0,0,-1,-1};
struct dot
{
	int x,y,step;
};
queue<dot> q;
int main()
{
	int n,x,y;
	dot start;
	cin>>n;
	for(int j=0;j<n;j++)
	{
		int p,f=0;
		memset(chs,0,sizeof(chs));
		memset(vis,0,sizeof(vis));
		while(!q.empty())q.pop();
		cin>>p;
		for(int i=0;i<2*p-2;i++)
		{
			cin>>x>>y;
			x--;
			y--;
			chs[x][y]=i+1;
		}
		start.x=0;
		start.y=0;
		start.step=0;
		q.push(start);
		vis[0][0]=1;
		while(!q.empty())
		{
			dot now=q.front();
			q.pop();
			if(now.x==n-1&&now.y==n-1)
			{
				cout<<"Yes\n";
				f=1;
				break;
			}
			for(int i=0;i<4;i++)
			{
				dot New;
				New.x=now.x+dx[i];
				New.y=now.y+dy[i];
				New.step=now.step+1;
				cout<<New.x<<' '<<New.y<<' '<<New.step<<'\n';
				if(New.x<0||New.x>=n||New.y<0||New.y>=n||chs[New.x][New.y]!=0&&chs[New.x][New.y]<New.step||vis[New.x][New.y])continue;
				q.push(New);
				vis[New.x][New.y]=1;
			}
		}
		if(!f)cout<<"No\n";
	}
	return 0;
}
2022/2/11 16:21
加载中...