求助
查看原帖
求助
912066
Andy2011_swsgroitfh楼主2024/3/31 15:18
#include <bits/stdc++.h>
using namespace std;
struct node
{
	int x, y;
	int stp;
};
int m;
int mapp[310][310];
bool vis[310][310];
int dx[] = {0, -1, 0, 0, 1};
int dy[] = {0, 0, -1, 1, 0};
int main()
{
	memset(mapp,-1,sizeof(mapp));
	cin>>m;
	int x, y, t;
	for (int i = 1; i <= m; i ++)
	{
		cin>>x>>y>>t;
		for (int j = 0; j <= 4; j ++)
		{
			if (x+dx[j]>=0 && y+dy[j]>=0 && (mapp[x+dx[j]][y+dy[j]]>t||mapp[x+dx[j]][y+dy[j]]==-1))
			{
				mapp[x+dx[j]][y+dy[j]] = t;
			}
		}
	}
	queue<node> q;
	vis[0][0] = true;
	q.push({0,0,0});
	while (!q.empty())
	{
		node h = q.front();
		q.pop();
		if (mapp[h.x][h.y] == -1)
		{
			cout<<h.stp;
			return 0;
		}
		for (int i = 1; i <= 4; i ++)
		{
			int nx = h.x+dx[i];
			int ny = h.y+dy[i];
			if (nx>=0 && ny>=0 && h.stp<mapp[nx][ny] &&!vis[nx][ny])
			{
				vis[nx][ny] = true;
				q.push({nx,ny,h.stp+1});
			}
		}
	}
	cout<<-1;
}

样例过不了:(

2024/3/31 15:18
加载中...