UVALive 4487 异或 并查集
来源:互联网 发布:淘宝店怎么设置限购 编辑:程序博客网 时间:2024/05/22 00:25
题目点这
位运算很强大啊
题解看着
这个题解中文讲解很详细,个人感觉代码上稍微有点繁琐,但总体很容易看懂
其他几个题解,代码看一眼,先来十几个define,,,GG
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int N=23333,T=N-10;int n,Q,op,p,q,va,k,ans,cas=1;int home[N],v[N],a[20],vis[N];bool ok;int FIND(int x){ if (home[x]==x)return x; int kk=home[x]; home[x]=FIND(home[x]); v[x]^=v[kk]; return home[x];}bool check(int i,int j,int va){ int r1=FIND(i),r2=FIND(j); if (r1==r2)return (v[i]^v[j])==va; if (r1==T ) swap(r1,r2); home[r1] = r2; v[r1]=v[i]^v[j]^va; return 1;}int main(){ //freopen("fuck.in","r",stdin); for (;scanf("%d%d",&n,&Q)==2;cas++){ if (n==0&&Q==0)break; printf("Case %d:\n",cas); for (int i=0;i<=n+1;i++)home[i]=i; memset(v,0,sizeof(v)); home[T]=T; ok=1; op=0; for (int time=0;time<Q;time++){ char ch[2]; scanf("%s",ch); if (ch[0]=='I') { char st[55]; gets(st); op++; if (sscanf(st,"%d%d%d",&p,&q,&va)==2) { va = q ; q = T ; } if (!ok)continue; if (!check(p,q,va)){ ok=0; printf("The first %d facts are conflicting.\n",op); } } else { ans=0; scanf("%d",&k); memset(vis,0,sizeof(vis)); for (int i=0;i<k;i++){ scanf("%d",&a[i]); if (!ok)continue; int root=FIND(a[i]); ans^=v[a[i]]; a[i]=root; vis[root]^=1; } if (!ok)continue; bool okk=1; for (int i=0;i<k;i++) if (vis[a[i]]&&a[i]!=T)okk=0; if (okk)printf("%d\n",ans); else puts("I don't know."); } } puts(""); } return 0;}
hust抽风了一下
最后是这样
两发WA是因为从pdf里面复制 I don’t know 的时候
粘到txt里面就变成了I don‘t know,坑爹啊
0 0
- UVALive 4487 异或 并查集
- UVALive - 3644 并查集
- UVALive 6187 并查集
- uvalive 3644(并查集)
- uvalive 3027(并查集)
- UVALive - 4487 Exclusive-OR 加权并查集
- UVALIVE 4487 Exclusive-OR(加权并查集)
- UVALive 4487 - Exclusive-OR -并查集 虚根
- X-Plosives +uvalive+并查集+水题
- Corporative Network +uvalive+并查集
- UVALive 6091 - Trees (并查集)
- 【UVALive】6168 Fat Ninjas 并查集
- UVALive 3644 X-Plosives 并查集
- UVALive 6091 Trees 并查集(水
- UVALive - 3644 X-Plosives 并查集
- UVALive 4627 -- Islands (并查集)
- UVALive - 3644 X-Plosives 并查集
- UVALive - 3027 Corporative Network 并查集
- MySQL修改数据表存储引擎的3种方法介绍
- js 默认的参数、可变的参数、变量作用域
- Linux环境搭建nginx+2个tomcat+2个redis(主从复制)
- Linux网络编程 -- 网络模型与通信过程
- TensorFlow Installation
- UVALive 4487 异或 并查集
- 吕鑫MFC学习系列六
- iOS之NSDate
- 栈的应用--四则运算表达式求值(java代码)
- Socket的简单认识
- 积跬步至千里系列之九--Android系统设置(二)
- 107. Binary Tree Level Order Traversal II LeetCode
- LeetCode 237. Delete Node in a Linked List
- App上线流程