求助 广搜板子题
  • 板块灌水区
  • 楼主az0913
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/20 11:07
  • 上次更新2023/11/3 02:30:23
查看原帖
求助 广搜板子题
707386
az0913楼主2023/8/20 11:07

代码

#include <bits/stdc++.h>
using namespace std;
const int N=110;
struct stu{
	int i;int j;
}q[10000];
int n,m,a[N][N],fx[5]={0,0,1,0,-1},fy[5]={0,1,0,-1,0};
int main()
{
	cin>>n>>m;
	int head=1,tail=0;
	tail++;
	q[tail].i=1;
	q[tail].j=1;
	a[1][1]=tail;
	while(head<=tail)
	{
		stu h=q[head];
		for(int k=1;k<=4;k++)
		{
			int tx=h.i+fx[k];
			int ty=h.j+fy[k];
			//stu t={h.i+fx[k],h.j+fy[k]};
			if(tx>=1&&tx<=n&&ty>=1&&ty<=n&&a[tx][ty]==0)
			{
				tail++;
				q[tail].i=tx;
				q[tail].j=ty;
				a[tx][ty]=tail;
			}
		}
		head++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

这是题 问题 第二个点就超时了

2023/8/20 11:07
加载中...