蒟蒻28分求助,只有前4个AC
查看原帖
蒟蒻28分求助,只有前4个AC
908988
Zailu楼主2023/2/21 20:35
#include<bits/stdc++.h>
using namespace std;
const int maxn=310;
struct coord
{
	int mt=2000,t=0,x=0,y=0;//mt记录变成焦土时的时间,t记录走到该处时的时间
	bool v,v1;//v记录是否已经成为焦土,避免记录焦土坐标时重复。v1记录奶牛是否已经走过该格
};
coord t[maxn][maxn];
int movx[5]={1,-1,0,0,0};
int movy[5]={0,0,-1,1,0};
int m;
queue<coord> q;
int main()
{
	cin>>m;
	for(int j=1;j<=m;j++)
	{
		int x,y,mtt;
		cin>>x>>y>>mtt;
		for(int i=0;i<5;i++)
		{
			if(x+movx[i]>=0&&y+movy[i]>=0&&t[x+movx[i]][y+movy[i]].v==0)
			{
				t[x+movx[i]][y+movy[i]].mt=mtt;
				t[x+movx[i]][y+movy[i]].v=1;
			}
		}

	}
	t[0][0].v1=1;
	q.push(t[0][0]);
	while(!q.empty())
	{
		coord now=q.front();
		q.pop();
		if(now.mt==2000)
		{
			cout<<now.t;
			return 0;
		}
		for(int i=0;i<4;i++)
		{
			int sx=now.x+movx[i];
			int sy=now.y+movy[i];
			if(sx>=0&&sy>=0)
			{
				if(now.t<t[sx][sy].mt-1&&t[sx][sy].v1==0)
				{
					t[sx][sy].x=sx;
					t[sx][sy].y=sy;
					t[sx][sy].t=now.t+1;
					t[sx][sy].v1=1;
					q.push(t[sx][sy]);
				}	
			}
		}
	}
	cout<<-1;
	return 0;
}
2023/2/21 20:35
加载中...