bzoj 3563: DZY Loves Chinese 并查集+乱搞
来源:互联网 发布:美军战斗力知乎 编辑:程序博客网 时间:2024/05/16 02:58
题目:传送门
分析:好好的,仔细的多看几遍题目,你就会惊奇地发现:沃日怎么连k都要异或。
那岂不是说可以直接得到上一行的答案!?
是的没错……
那么我们只要把最后一行搞一搞就好了。
注意每一行的结尾会有各种各样乱七八糟的符号。
代码:
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#define N 100005using namespace std;int f[N],a[N];char str[N*100];struct edge{int x,y,f;}e[N*5];int read(){ int f=1,x=0;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 find(int x){ if (f[x]==x) return x; f[x]=find(f[x]); return f[x];}int main(){ int n=read(),m=read(); for (int i=1;i<=m;i++) { e[i].x=read();e[i].y=read(); } int q=read(); int w=read(); gets(str); int l=strlen(str); while (1) { if (str[l-1]>='0'&&str[l-1]<='9') break; l--; str[l]='\0'; } int k=0,x=0; for (int i=0;i<strlen(str);i++) { if (str[i]>='0'&&str[i]<='9') x=x*10+str[i]-'0'; else { a[++k]=x; x=0; } } a[++k]=x; int lastans=0; for (int j=2;j<=q;j++) { int w=read(); gets(str); int l=strlen(str); while (1) { if (str[l-1]>='0'&&str[l-1]<='9') break; l--; str[l]='\0'; } x=0;k=0; for (int i=0;i<strlen(str);i++) if (str[i]>='0'&&str[i]<='9') x=x*10+str[i]-'0'; else { a[++k]=x; x=0; } a[++k]=x; if ((w^k)-lastans==1) { lastans++; printf("Connected\n"); } else printf("Disconnected\n"); } for (int i=1;i<=k;i++) a[i]^=lastans; for (int i=1;i<=k;i++) e[a[i]].f=1; for (int i=1;i<=n;i++) f[i]=i; int ans=n; for (int i=1;i<=m;i++) if (!e[i].f&&find(e[i].x)!=find(e[i].y)) { ans--; f[find(e[i].x)]=find(e[i].y); } if (ans==1) printf("Connected\n"); else printf("Disconnected\n"); return 0;}
0 0
- [乱搞 暴力 并查集] BZOJ 3563 DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese 并查集+乱搞
- BZOJ 3563 DZY Loves Chinese 并查集
- bzoj 3563: DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- 【bzoj3563】DZY Loves Chinese 在线cdq分治+并查集
- BZOJ 3563 DZY Loves Chinese / BZOJ 3569 DZY Loves Chinese II 随机化+高斯消元解异或方程组
- BZOJ 3569 DZY Loves Chinese(BZOJ 3563) II 线性基
- [bzoj 3563&3569]DZY Loves Chinese I&II
- BZOJ 3563 DZY Loves Chinese(线性基)
- BZOJ 3569 DZY Loves Chinese II 高斯消元
- bzoj 3569: DZY Loves Chinese II
- BZOJ 3569: DZY Loves Chinese II
- BZOJ 3520: Dzy loves chemistry 1【并查集,卡精度
- 【bzoj 3739】DZY loves math VIII - 乱搞数学题
- CodeForces 445B. DZY Loves Chemistry(并查集)
- Codeforces 445B DZY Loves Chemistry(并查集)
- 大数据Spark “蘑菇云”行动第61课: 广告点击系统时间管理和数据库分层
- Matlab的数据操作
- Android 在Fragment中对Menu的操作
- PHP魔术常量常量(预定义常量)
- Android Parcelable和Serializable的区别
- bzoj 3563: DZY Loves Chinese 并查集+乱搞
- php基础(五)
- selenium(java)之操作vedio,audio
- Eclipse中导入外部jar包
- Xcafe:Netty实现兼容SpringMVC的Web容器
- 2016年10月17日 学习笔记
- hdu4003
- 父窗口操控iframe
- Android Fragment 真正的完全解析(下)