为啥我的代码运行不了
查看原帖
为啥我的代码运行不了
1219892
hjxiang楼主2024/6/5 22:49
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define int long long
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define lowbit(x) ((x) & (-x))
const int mod = 1e9+7;
const int inf = 1e9+7;
typedef pair<int,int> pii;
typedef pair<int ,pair <int ,int> > piii;
const int N=5e4+5;
int next1[4][2]={0,1,1,0,0,-1,-1,0};
int a[405][405],b[405][405],c[305][305],x[N],y[N],t[N];
int n,m,k;
void solve()
{
	for(int i=0;i<405;i++)
		for(int j=0;j<405;j++)
		b[i][j]=1,a[i][j]=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>y[i]>>t[i];
		b[x[i]][y[i]]=0;
		for(int j=0;j<4;j++)
		{
			int tx=x[i]+next1[j][0];
			int ty=y[i]+next1[j][1];
			b[tx][ty]=0;
		}
	}
	queue<piii> s;
	int idx=1;
	s.push({0,{0,0}});
	c[0][0]=1;
	while(!s.empty())
	{
		auto [tt,w]=s.front();
		auto [xx,yy]=w;
		s.pop();
		cout<<xx<<yy<<endl;
		cout<<a[xx][yy]<<endl;
		if(b[xx][yy])
		{
			cout<<tt<<endl;
			return;
		}
		cout<<tt<<endl;
		while(tt==t[idx]&&idx<=n)
		{
				int tx=x[idx];
				int ty=y[idx];
				a[tx][ty]=0;
				a[tx+1][ty]=0;
				a[tx-1][ty]=0;
				a[tx][ty+1]=0;
				a[tx][ty-1]=0;
			    idx+=1;
		}
		if(a[xx][yy])
		{
			for(int i=0;i<4;i++)
			{
				int tx=xx+next1[i][0];
				int ty=yy+next1[i][1];
				if(a[tx][ty]&&tx>=0&&ty>=0&&tx<=300&&ty<=300&&!c[tx][ty])
				{
					s.push({tt+1,{tx,ty}});
					c[tx][ty]=1;
				}
			}
		}
	}
	cout<<"-1"<<endl;
}
signed main()
{
//	 cin.tie(0);
//	 cout.tie(0);
//	 ios::sync_with_stdio(false);
//  int t;
   // t=1;
    //cin>>t;
//    while(t--)
    solve();
}
2024/6/5 22:49
加载中...