bzoj 4423: [AMPPZ2013]Bytehattan 并查集
来源:互联网 发布:华帝 方太 老板知乎 编辑:程序博客网 时间:2024/06/06 06:58
题意
比特哈顿镇有n*n个格点,形成了一个网格图。一开始整张图是完整的。
有k次操作,每次会删掉图中的一条边(u,v),你需要回答在删除这条边之后u和v是否仍然连通。
n<=1500
分析
这题由于是网格图,所以肯定跟网格图的性质有关。
如果我们把每个方格看做一个点,考虑如果新删掉的边使这两个点不连通,则必然有这条边两侧的方格是联通的。这个只要画一下图就明白了。
直接并查集硬上即可。
代码
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;const int N=3000005;int n,m,f[N];int read(){ int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int point(int x,int y){ return x*n+y;}int find(int x){ if (f[x]==x) return x; f[x]=find(f[x]); return f[x];}int main(){ n=read();m=read(); for (int i=1;i<=n*n;i++) f[i]=i; for (int i=0;i<=n;i++) f[point(i,0)]=f[point(0,i)]=f[point(i,n)]=f[point(n,i)]=0; int ans=0; while (m--) { int x1=read(),y1=read(),x,y;char op1[2],op2[2],op[2]; scanf("%s",op1); int x2=read(),y2=read();scanf("%s",op2); if (!ans) x=x1,y=y1,op[0]=op1[0]; else x=x2,y=y2,op[0]=op2[0]; int a=find(point(x,y)),b=find(op[0]=='N'?point(x-1,y):point(x,y-1)); if (a==b) ans=1,puts("NIE"); else ans=0,puts("TAK"),f[a]=b; } return 0;}
阅读全文
0 0
- bzoj 4423: [AMPPZ2013]Bytehattan 并查集
- [平面图 并查集] BZOJ 4423 [AMPPZ2013]Bytehattan
- BZOJ 4423: [AMPPZ2013]Bytehattan 并查集 平面图转对偶图
- 4423: [AMPPZ2013]Bytehattan|并查集|平面图转对偶图
- 4423: [AMPPZ2013]Bytehattan 平面图转对偶图+并查集
- bzoj 4423: [AMPPZ2013]Bytehattan
- bzoj 4423: [AMPPZ2013]Bytehattan
- [BZOJ4423] [AMPPZ2013] Bytehattan - 平面图 - 并查集
- BZOJ4423: [AMPPZ2013]Bytehattan(并查集,对偶图)
- BZOJ 4423 AMPPZ 2013 Bytehattan 平面图 并查集
- BZOJ 4423 Bytehattan (对偶图 并查集)
- BZOJ4423: [AMPPZ2013]Bytehattan
- BZOJ4423: [AMPPZ2013]Bytehattan
- BZOJ 1202 并查集
- BZOJ 1015 并查集
- BZOJ 1854 并查集
- BZOJ 1015 并查集
- bzoj 1529 并查集
- Mean Average Precise理解及源码分析
- 元素外边距合并产生问题
- TopN算法
- POJ
- 自定义MVC框架(分页前台部分)
- bzoj 4423: [AMPPZ2013]Bytehattan 并查集
- 扫盲系列—正向代理和反向代理
- 利用MOS管和稳压二极管来做保护电路
- ios-UIGesture扩展手势
- React Component 的生命周期 API
- 数组迭代器(一)-《数据结构预算法》
- gcc -fPIC 选项
- face++人脸识别接口实现原理(一)
- 技巧篇