码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj4423 [AMPPZ2013]Bytehattan

时间:2017-05-30 19:45:50      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:names   class   play   www   --   end   nbsp   problem   hid   

传送门: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

标签:names   class   play   www   --   end   nbsp   problem   hid   

原文地址:http://www.cnblogs.com/galaxies/p/bzoj4423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!