92分求条(Wa on#14)
查看原帖
92分求条(Wa on#14)
1407732
Lihy2010楼主2025/7/24 13:07

Wrong Answer.wrong answer On line 1 column 1, read -, expected 4.

#include<bits/stdc++.h>
#define rep1 for(int i=1;i<=n;i++)
using namespace std;
const int N=313;
int n,a[N][N],t[N][N],ans;
const int M=1e9;
int nx[5]={0,1,0,-1,0};
int ny[5]={0,0,1,0,-1};
struct zb{
	int x,y;
};
queue<zb> q;
bool f;

bool check(int xx,int yy){
	if(xx<0||xx>300||yy<0||yy>300) return 0;
	if(t[xx][yy]) return 0;
	return 1;
}
int bfs(zb stt)
{
	q.push(stt);
	while(!q.empty()){
		zb nw=q.front();q.pop();
		for(int i=1;i<=4;i++){
			zb nt={nw.x+nx[i],nw.y+ny[i]};
			if(check(nt.x,nt.y))
			if(t[nw.x][nw.y]<a[nt.x][nt.y]-1){
				t[nt.x][nt.y]=t[nw.x][nw.y]+1;
				if(a[nt.x][nt.y]==M){return t[nt.x][nt.y];}
				q.push(nt);
			}
		}		
	}
	return -1;
}
int main()
{
	for(int i=0;i<=N-1;i++)
		for(int j=0;j<=N-1;j++)
		    a[i][j]=M;
	cin>>n;
	int tx,ty,tt;
	rep1{
		scanf("%d%d%d",&tx,&ty,&tt);
		for(int j=0;j<=4;j++)
		if(check(tx+nx[j],ty+ny[j]))
		a[tx+nx[j]][ty+ny[j]]=min(a[tx+nx[j]][ty+ny[j]],tt);
	}
	zb stt={0,0};
	cout<<bfs(stt);
 	return 0;
}

一个小小的bfs有没有大佬可以帮忙调一下 在下万分感谢

2025/7/24 13:07
加载中...