社区讨论

求 G 悬关

学术版参与者 5已保存回复 8

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
8 条
当前快照
1 份
快照标识符
@mhjq6lz6
此快照首次捕获于
2025/11/04 06:42
4 个月前
此快照最后确认于
2025/11/04 06:42
4 个月前
查看原帖
WA*2 是啥啊/fn/fn/fn
CPP
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
int n, m, k;
int x, y;
map<int, map<int, int>> h;
queue<pair<int, int>> q;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
map<int, map<int, int>> vis;
main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= k; i++)
    {
        cin >> x >> y;
        h[x][y] = 1;
        if (x == n || y == 1)
            q.push(mp(x, y)), vis[x][y] = 1;
    }
    while (!q.empty())
    {
        pair<int, int> t = q.front();
        q.pop();
        for (int i = 0; i < 8; i++)
        {
            int tx = t.first + dx[i];
            int ty = t.second + dy[i];
            if (tx > 0 && ty > 0 && tx <= n && ty <= m && h[tx][ty] && !vis[tx][ty])
            {
                q.push(mp(tx, ty));
                vis[tx][ty] = 1;
                if (tx == 1 || ty == m)
                {
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes";
    return 0;
}

回复

8 条回复,欢迎继续交流。

正在加载回复...