求助#20
查看原帖
求助#20
1179906
hhy8399楼主2024/6/2 13:57
#include<bits/stdc++.h>
using namespace std;

char a[10005][10005];
int tag[10005][10005],ans = 1;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
int n,m; 

struct node{
	int x,y;
};


queue <node> q;
void bfs(){
	node tmp;
	tmp.x = 1,tmp.y = 1;
	q.push(tmp);
	tag[1][1] = 1;
	while(!q.empty())
	{
		tmp = q.front();
		q.pop();
		for(int i = 0;i < 4;i++)
		{
			int tx = tmp.x+dx[i];
			int ty = tmp.y+dy[i];
			if(tx >= 1 && ty >= 1 && ty <= m && tx <= n && tag[tx][ty] == 0 && a[tx][ty] == '.')
			{
				node t;
				t.x = tx,t.y = ty;
				q.push(t);
				tag[tx][ty] = 1;
				cout << tx << " " << ty << "\n";
			}
		}
	}
}

int main()
{
    cin >> n >> m;
    for(int i = 1;i <= n;i++){
    	for(int j = 1;j <= m;j++)
		{
    		cin >> a[i][j];
    	}
    }
    cout << "1 1\n";
    bfs();
	
	return 0;
}

20分

2024/6/2 13:57
加载中...