bzoj 4423: [AMPPZ2013]Bytehattan
来源:互联网 发布:淘宝联盟结算第三方 编辑:程序博客网 时间:2024/06/05 11:45
题意:
在平面图上,每次删一条边,问它连向的两个点是否还连通。
题解:
假如可以离线就可以乱搞。
但是强制在线。
于是有个脑洞很大的做法。
对偶图+并查集。
每次将割的边的两边的平面连在一起。
假如他么本来就在一个并查集中,那么说明有一个空缺的环将两个点分开,于是就不连通了,否则否则反之。
我个sb输出没换行竟然没看出来。
code:
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>using namespace std;int fa[6000010];int n,k,last=1;int qs(int x,int y){return (x-1)*(n+1)+y;}int findfa(int x){ if(fa[x]!=x) fa[x]=findfa(fa[x]); return fa[x];}void ins(int x,int y){ int tx=findfa(x),ty=findfa(y); if(tx!=ty) fa[tx]=ty;}int main(){ scanf("%d %d",&n,&k); for(int i=1;i<=(n+1)*(n+1);i++) fa[i]=i; for(int i=2;i<=n+1;i++) ins(qs(1,i),qs(1,i-1)); for(int i=2;i<=n+1;i++) ins(qs(i,n+1),qs(i-1,n+1)); for(int i=n;i>=1;i--) ins(qs(n+1,i),qs(n+1,i+1)); for(int i=n;i>=1;i--) ins(qs(i,1),qs(i+1,1)); while(k--) { int x1,y1,x2,y2,x,y;char c1,c2,c; scanf("%d %d %c %d %d %c",&x1,&y1,&c1,&x2,&y2,&c2); if(last==1) x=x1,y=y1,c=c1; else x=x2,y=y2,c=c2; int X,Y; if(c=='N') X=qs(x,y+1),Y=qs(x+1,y+1); else X=qs(x+1,y),Y=qs(x+1,y+1); int tx=findfa(X),ty=findfa(Y); if(tx==ty) last=0; else last=1,fa[tx]=ty; if(last==1) printf("TAK\n"); else printf("NIE\n"); }}
阅读全文
1 0
- bzoj 4423: [AMPPZ2013]Bytehattan
- bzoj 4423: [AMPPZ2013]Bytehattan
- bzoj 4423: [AMPPZ2013]Bytehattan 并查集
- [平面图 并查集] BZOJ 4423 [AMPPZ2013]Bytehattan
- BZOJ 4423: [AMPPZ2013]Bytehattan 并查集 平面图转对偶图
- BZOJ4423: [AMPPZ2013]Bytehattan
- BZOJ4423: [AMPPZ2013]Bytehattan
- 4423: [AMPPZ2013]Bytehattan|并查集|平面图转对偶图
- 4423: [AMPPZ2013]Bytehattan 平面图转对偶图+并查集
- [BZOJ4423] [AMPPZ2013] Bytehattan - 平面图 - 并查集
- BZOJ4423: [AMPPZ2013]Bytehattan(并查集,对偶图)
- BZOJ 4423 AMPPZ 2013 Bytehattan 平面图 并查集
- BZOJ 4423 Bytehattan (对偶图 并查集)
- [BZOJ ]
- BZOJ****-****
- BZOJ
- BZOJ
- BZOJ
- 排序的Java实现
- Java学习笔记之IO(十七):转换流
- C语言除法”四舍五入“与“进一法”的实现
- sqoop mysql 抽到hive
- 云栖大会之异构计算,12日,B-3-5不见不散。
- bzoj 4423: [AMPPZ2013]Bytehattan
- CodeForces
- 给定中序-先序,中序-后序序列构建二叉树的算法
- C语言和C++ C#的区别在什么地方?
- retrofit的使用
- C++ STL系列之 STL标准入门必读
- 485芯片中slew-rate-limited是什么意思(转)
- git,掌握这些就够了
- 常用 Git 命令清单