谁知道怎么回事?
查看原帖
谁知道怎么回事?
183685
Tyler0819楼主2020/7/25 21:04
#include <iostream>
#include <queue>
using namespace std;
const int N = 113 + 5;
struct Node
{
    int x,y;
};
int r,c;
int map[N][N];
bool vis[N][N];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool in(int x,int y)
{
    return 1 <= x && x <= r && 1 <= y && y <= c;
}
void bfs()
{
    queue<Node> que;
    memset(vis,false,sizeof(vis));
    Node init;
    init.x = 1;
    init.y = 1;
    que.push(init);
    vis[1][1] = true;
    while(!que.empty())
    {
        Node now = que.front();
        que.pop();
        for(int i = 0; i < 4; i++)
        {
            int nx = now.x + dx[i];
            int ny = now.y + dy[i];
            if(!in(nx,ny))
            {
                continue;
            }
            if(!vis[nx][ny] && map[nx][ny] != '*')
            {
                Node next;
                next.x = nx;
                next.y = ny;
                que.push(next);
                vis[nx][ny] = true;
                cout << nx << " " << ny << endl;
            }
        }
    }
}
int main()
{
    cin >> r >> c;
    for(int i = 1; i <= r; i++)
    {
        for(int j = 1; j <= c; j++)
        {
            cin >> map[i][j];
        }
    }
    cout << 1 << " " << 1 << endl;
    bfs();
    return 0;
}

满江红啊

2020/7/25 21:04
加载中...