没有输出,RE + MLE
  • 板块P3395 路障
  • 楼主梦回江南
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/5/29 23:20
  • 上次更新2023/10/28 00:18:10
查看原帖
没有输出,RE + MLE
492676
梦回江南楼主2022/5/29 23:20
#include <queue>
#include <memory.h>
#include <iostream>
#include <algorithm>
// 数据类型简化
#define L unsigned long long
#define LL long long
#define I unsigned int
// cin/cout 优化
#define endl '\n'
// sort + unique
#define soun(nf, nl, m) \
    sort(nf, nl);       \
    m = unique(nf, nl) - (nf)
// for 循环简化
#define ref(i, a, b, p) for (signed(i) = (a); (i) <= signed(b); (i) += signed(p))
#define gef(i, a, b, p) for (signed(i) = (a); (i) >= signed(b); (i) -= signed(p))
using namespace std;

bool map[2005][2005];
int T, n;
struct node
{
    int x, y;
};
queue<node> st, q;
int wx[4] = {1, -1, 0, 0};
int wy[4] = {0, 0, 1, -1};

void bfs()
{
    bool flag = 0;
    q.push(node{1, 1});
    while (!q.empty())
    {
        node nw = q.front();
        q.pop();
        int x = nw.x, y = nw.y;
        map[x][y] = 1;
        ref(i, 0, 3, 1)
        {
            int nwx = x + wx[i], nwy = y + wy[i];
            if (nwx > n || nwx < 1 || nwy > n || nwy < 1 || map[nwx][nwy] == 1)
                continue;
            if (nwx == n && nwy == n)
            {
                flag = 1;
                break;
            }
            else
                q.push(node{nwx, nwy});
        }
        node nw1 = st.front();
        int x1 = x = nw1.x, y1 = nw1.y;
        map[x1][y1] = 1;
        st.pop();
        q.pop();
    }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return;
}

void work()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> T;
    ref(i, 1, T, 1)
    {
        
        while (!st.empty())
            st.pop();
        while (!q.empty())
            q.pop();
        cin >> n;
        ref(j, 1, 2 * n - 2, 1)
        {
            int x, y;
            cin >> x >> y;
            st.push(node{x, y});
        }
        // cout << 1 << endl;
        bfs();
    }

    return;
}

int main()
{
    work();

    return 0;
}

2022/5/29 23:20
加载中...