社区讨论
求助 广搜板子题
灌水区参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lo1ro163
- 此快照首次捕获于
- 2023/10/23 01:52 2 年前
- 此快照最后确认于
- 2023/11/03 02:30 2 年前
代码
CPP#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;
}
这是题
问题
第二个点就超时了
回复
共 0 条回复,欢迎继续交流。
正在加载回复...