求大佬找错
查看原帖
求大佬找错
247159
林楚颜楼主2021/3/13 17:06

在线等,挺急的;

太弱了,一个点都没过

#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,-1,1,1},dy[]={1,-1,1,-1};
struct data{
	int xx;
	int yy;
	int time;
} now,KKK,nn;
queue<data> q;
int M,XXX,YYY,TTT,qj[350][350],nc[350][350];
int main()
{
	cin>>M;
	memset(qj,-1,sizeof(qj));
	for(int i=1;i<=M;i++)
	{
		cin>>XXX>>YYY>>TTT;
		if(qj[XXX][YYY]==0) qj[XXX][YYY]=TTT;
	    if(XXX-1>=0&&YYY-1>=0&&qj[XXX-1][YYY-1]==0) qj[XXX][YYY]=TTT;
		if(XXX-1>=0&&YYY+1&&qj[XXX-1][YYY+1]==0) qj[XXX][YYY]=TTT;
	    if(XXX+1<=300&&YYY-1>=0&&qj[XXX+1][YYY-1]==0) qj[XXX][YYY]=TTT;
	    if(XXX-1<=300&&YYY-1<=300&&qj[XXX+1][YYY+1]==0) qj[XXX][YYY]=TTT;
    }
    KKK.xx=0;
    KKK.yy=0;
    KKK.time=0;
	q.push(KKK);
	while(!q.empty())
	{
		now=q.front();
		q.pop();
		for(int i=0;i<4;i++)
		{
			nn.xx=now.xx+dx[i];
			nn.yy=now.yy+dy[i];
			nn.time=now.time+1;
			if(nn.xx>=0&&nn.xx<=300&&nn.yy>=0&&nn.yy<=300)
			{
				if(qj[nn.xx][nn.yy]==-1)
				{
					cout<<nn.time;
					return 0;
				}
				if(nc[nn.xx][nn.yy]==0&&qj[nn.xx][nn.yy]>nn.time) q.push(nn);
			}
		}
	}
	cout<<-1;
	return 0;
}

2021/3/13 17:06
加载中...