RE求调
  • 板块灌水区
  • 楼主CMZ369
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/8/27 20:33
  • 上次更新2024/8/27 22:22:15
查看原帖
RE求调
1010237
CMZ369楼主2024/8/27 20:33

P1256 显示图像

被狠狠地RE了,但看不出哪错了。

RE记录

RE代码:

#include<bits/stdc++.h>
using namespace std;
int n,m,a[183][183],b[183][183],dis[183][183],xx[4]={0,0,1,-1},yy[4]={1,-1,0,0};
char c;
struct qwe
{
	int x,y,cnt;
}h;
queue<qwe> q;
int bfs()
{
	while(!q.empty())
	{
		h=q.front();
		q.pop();
		int x=h.x,y=h.y,cnt=h.cnt;
		dis[x][y]=cnt;
		for(int i=0;i<4;++i)
		{
			int dx=x+xx[i],dy=y+yy[i];
			if(dx>=1&&dx<=n&&dy>=1&&dy<=m&&!b[dx][dy]&&a[dx][dy]==0)
			{
				b[dx][dy]=1;
				qwe net;
				net.x=dx;net.y=dy;net.cnt=cnt+1;
				q.push(net);
			}
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>c;
			a[i][j]=c-'0';
			if(a[i][j]==1)
			{
				b[i][j]=1;
				q.push({i,j,0});
			}
		}
	}
	queue<int> p;
	p.pop();
	bfs();
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			printf("%d ",dis[i][j]);
		}
		putchar('\n');
	}
	return 0;
}

希望大佬看看那里出问题了

2024/8/27 20:33
加载中...