85分求助。
查看原帖
85分求助。
273217
Mithrandir楼主2020/7/21 17:55
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#pragma GCC optimize(2)
using namespace std;
struct Meteor
{
	int x,y;
	int t;
}s;
int m,mapp[305][305]={},cx,cy,ct;
int mx[5]={0,1,0,-1,0};
int my[5]={0,0,1,0,-1};
deque <Meteor> q;
int bfs()
{
	while(!q.empty())
	{
		for(int i=1;i<=4;i++)
		{
			Meteor n;
			n.x=q.front().x+mx[i];
			n.y=q.front().y+my[i];
			n.t=q.front().t+1;
			if(mapp[n.x][n.y]==0&&n.x<=300&&n.y<=300&&n.x>=0&&n.y>=0) return n.t;
			if(n.x<=300&&n.y<=300&&n.x>=0&&n.y>=0&&n.t<mapp[n.x][n.y]&&mapp[n.x][n.y]!=-1)
			q.push_back(n),mapp[n.x][n.y]=-1;
		}
		q.pop_front();
	}
	return -1;
}
int main()
{
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>cx>>cy>>ct;
		if(mapp[cx][cy]>ct||!mapp[cx][cy]) mapp[cx][cy]=ct;
		for(int j=1;j<=4;j++)
		if(mapp[cx+mx[j]][cy+my[j]]>ct&&cx+mx[j]>=0&&cy+my[j]>=0||!mapp[cx+mx[j]][cy+my[j]]&&cx+mx[j]>=0&&cy+my[j]>=0)
		mapp[cx+mx[j]][cy+my[j]]=ct;
	}
	/*for(int i=0;i<30;i++)
	{
		for(int j=0;j<30;j++)
		cout<<mapp[i][j]<<" ";
		cout<<endl;
	}*/
	s.t=0;s.x=0;s.y=0;
	q.push_back(s);
	cout<<bfs();
	return 0;
}

我比较好奇第3个点:

in

5

0 0 2

3 0 0

1 2 5

2 2 4

1 4 4

map

2 2 5 0 4 0 0

2 5 4 4 4 4 0

0 4 4 4 4 0 0

0 0 4 0 0 0 0

0 0 0 0 0 0 0

myout 2

answer 3

2020/7/21 17:55
加载中...