zoukankan      html  css  js  c++  java
  • bzoj4423 [AMPPZ2013]Bytehattan

    传送门

    分析

    我们考虑把网格图转换为一个对偶图

    然后我们每次删一条边就是将对偶图上对应的两个点用并查集连接起来

    每次查询看是否联通即可

    代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cctype>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    #include<queue>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    using namespace std;
    int n,m,fa[4000000];
    inline int sf(int x){return fa[x]==x?x:fa[x]=sf(fa[x]);}
    int main(){
        int i,j,k,wh=0;
        scanf("%d%d",&n,&m);
        n++;
        for(i=1;i<=n*n;i++)fa[i]=(i<=n||i>(n-1)*n||i%n==1||i%n==0)?1:i;
        for(i=1;i<=m;i++){
          int x,y,xx,yy;
          char s1[5],s2[5];
          scanf("%d%d",&x,&y);
          scanf("%s",s1);
          scanf("%d%d",&xx,&yy);
          scanf("%s",s2);
          if(wh){
            x=xx;
            y=yy;
            s1[0]=s2[0];
          }
          xx=sf(x*n+y+1);
          if(s1[0]=='N')yy=sf((x-1)*n+y+1);
            else yy=sf(x*n+y);
          if(xx!=yy){
            wh=0;
            puts("TAK");
            fa[xx]=yy;
          }else {
            wh=1;
            puts("NIE");
          }
        }
        return 0;
    }
  • 相关阅读:
    加关注
    UI设计
    敏捷开发
    java书箱
    怎么优化JAVA程序的执行效率和性能?
    sql访注入
    Matlab中plot函数全功能解析
    matlab分割背景与物体
    ssh免密码登录
    c++字符串详解(转)
  • 原文地址:https://www.cnblogs.com/yzxverygood/p/10009675.html
Copyright © 2011-2022 走看看