bzoj 4423: [AMPPZ2013]Bytehattan

题解

今天来学了一波平面图转对偶图。。
感觉很妙啊。。
但是我似乎并不能很好地认清平面图和对偶图
CODE:

#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=1505;
int M;
int f[N*N];
int n,k;
int m;
int last=1;
int find (int x){return f[x]==x?f[x]:f[x]=find(f[x]);}
int P (int x,int y){return (x-1)*m+y;}
void Ins (int x,int y)//这两个点连通 
{
    int fx=find(x),fy=find(y);
    f[fx]=fy;
}
void solve (int x,int y,char ch)
{
    int a,b;
    if (ch=='E') a=P(x+1,y),b=P(x+1,y+1);
    else a=P(x,y+1),b=P(x+1,y+1);
    int fx=find(a),fy=find(b);
    if (fx==fy)
    {
        last=0;
        printf("NIE\n");
    }
    else
    {
        last=1;
        f[fx]=fy;
        printf("TAK\n");
    }
}
int main()
{
    scanf("%d%d",&n,&k);
    m=n+1;M=m*m;
    for (int u=1;u<=M;u++) f[u]=u;
    for (int u=2;u<=m;u++) Ins(P(1,u),P(1,u-1));
    for (int u=2;u<=m;u++) Ins(P(m,u),P(m,u-1));
    for (int u=2;u<=m;u++) Ins(P(u,1),P(u-1,1));
    for (int u=2;u<=m;u++) Ins(P(u,m),P(u-1,m));
    while (k--)
    {
        int a,b,c,d;char ss[5],ss1[5];
        scanf("%d%d",&a,&b);scanf("%s",ss);
        scanf("%d%d",&c,&d);scanf("%s",ss1);
        if (last==1) solve(a,b,ss[0]);
        else  solve(c,d,ss1[0]);
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值