代码何故 RE,我求理由
查看原帖
代码何故 RE,我求理由
123021
Meatherm_test楼主2020/12/15 22:04

如题,帮人问的

初步测出来是输入的最后一行导致 RE

但是我退役太久...看不出来了,也许各位可以?

#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using std::cin;
using std::cout;
using std::endl;
using std::memset;
using std::queue;
using std::min;
struct Coord
{
	int x,y;
};
int m,ANS=1e5,map[310][310],ans[310][310];
int wk[10][5]={{0,0},{1,0},{0,1},{-1,0},{0,-1}};
queue<Coord> Q;
int main()
{
	memset(map,127,sizeof(map));
	memset(ans,-1,sizeof(ans));
	cin>>m;
	for(int i=0;i<m;i++)
	{
		int x,y,t;
		cin>>x>>y>>t;
	    for(int j=0;j<5;j++)
	     if(x+wk[j][0]>=0 && y+wk[j][1]>=0)
		 	if(t<map[x+wk[j][0]][y+wk[j][1]])
	      	  map[x+wk[j][0]][y+wk[j][1]]=t;
	}
    Q.push((Coord){0,0});
    while(!Q.empty())
    {
    	Coord u=Q.front();
    	ans[0][0]=0;
    	int ux=u.x,uy=u.y;
    	Q.pop();
    	for(int j=1;j<5;j++)
    	{
    		int x=ux+wk[j][0],y=uy+wk[j][1];
    		if(x<0 || y<0 )
    		 continue;
    		if(ans[x][y]!=-1 || ans[ux][uy]+1>=map[x][y])
    		  continue;
    		ans[x][y]=ans[ux][uy]+1;
    		Q.push((Coord){x,y});
		}
	}
	for(int i=0;i<=305;i++)
	 for(int j=0;j<=305;j++)
	  if(map[i][j]>1000 && ans[i][j]!=-1)
	   ANS=min(ANS,ans[i][j]);
	if(ANS==1e5)
	 cout<<-1;
	else
	 cout<<ANS;
return 0;
}
2020/12/15 22:04
加载中...