bzoj4423 [AMPPZ2013]Bytehattan

Posted 逢山开路 遇水架桥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj4423 [AMPPZ2013]Bytehattan相关的知识,希望对你有一定的参考价值。

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4423

【题解】

转对偶图,格子当成点,就相当于并查集裸题了。。

技术分享
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 3e6 + 10, N = 1510;
const int mod = 1e9+7;

# define RG register
# define ST static

int n, q, out, idx;
int id[N][N], fa[M];

inline int getf(int x) {
    return fa[x] == x ? x : fa[x] = getf(fa[x]);
}

int main() {
    cin >> n >> q;
    for (int i=1; i<=n-1; ++i)
        for (int j=1; j<=n-1; ++j)
            id[i][j] = ++idx;
    out = ++idx;
    for (int i=1; i<=idx; ++i) fa[i] = i;
    bool o = 0;
    int x, y, u, v, fu, fv; char opt[5];
    while(q--) {
        if(o) scanf("%*d%*d%*s%d%d%s", &x, &y, opt);
        else scanf("%d%d%s%*d%*d%*s", &x, &y, opt);
        if(opt[0] == N) {
            // (x,y)->(x,y+1)
            if(x == 1) u = out;
            else u = id[x-1][y];
            if(x == n) v = out;
            else v = id[x][y];
        }
        if(opt[0] == E) {
            // (x,y)->(x+1,y)
            if(y == 1) u = out;
            else u = id[x][y-1];
            if(y == n) v = out;
            else v = id[x][y];
        }
//        cout << u << ‘ ‘ << v << endl;
        fu = getf(u);
        fv = getf(v);
        if(fu == fv) o = 1;
        else o = 0;
        if(fu != fv) fa[fu] = fv;
        puts(o ? "NIE" : "TAK");
    }
    return 0;
}
View Code

 

以上是关于bzoj4423 [AMPPZ2013]Bytehattan的主要内容,如果未能解决你的问题,请参考以下文章

bzoj 4423: [AMPPZ2013]Bytehattan

bzoj 4423 [AMPPZ2013]Bytehattan(对偶图,并查集)

bzoj4423 AMPPZ2013—Bytehattan

Bzoj4423 [AMPPZ2013]Bytehattan

BZOJ4423 [AMPPZ2013]Bytehattan

[BZOJ 4423][AMPPZ2013]Bytehattan