题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3949
这个题ihopenot都说是水题了,那我也扔一份代码就跑吧!
想看题解的戳这里:http://acm.hdu.edu.cn/showproblem.php?pid=3949
#include<bits/stdc++.h> #define LL long long using namespace std; const int N = 10000+9; int n,bas[70],cnt,m; LL arr[N],l,r,STA,tag; inline void insert(LL &w, int num) { for (int i=61;~i;i--) if (w & (1LL<<i)) { if (bas[i]) { w ^= arr[bas[i]]; } else { bas[i] = num; break; } } if (!w) tag = 1; } inline LL cal(LL w) { LL ret = 0; for (int i=0,cur=0;i<cnt;i++) { while (!bas[cur]) cur++; if (w&(1LL<<i)) ret ^= arr[bas[cur]]; cur++; } return ret; } inline int read(){ char c=getchar(); int ret=0,f=1; while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();} while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();} return ret*f; } int main(){ for (int T=read(),tot=1;T;T--,tot++) { printf("Case #%d:\n",tot); memset(bas,0,sizeof(bas)); memset(arr,0,sizeof(arr)); cnt = tag = 0; n = read(); for (int i=1;i<=n;i++) { cin>>arr[i]; insert(arr[i],i); } for (int i=0;i<=61;i++) if (bas[i]) { ++cnt; for (int j=i+1;j<=61;j++) if (bas[j]) { if (arr[bas[j]] & (1LL<<i)) { arr[bas[j]] ^= arr[bas[i]]; } } } m = read(); STA = (1LL<<cnt) - 1; for (int i=1;i<=m;i++) { LL tmp; scanf("%I64d",&tmp); tmp -= tag; if (STA < tmp) puts("-1"); else printf("%I64d\n",cal(tmp)); } } return 0; }
Thanks for every other fantastic article. Where else may anyone get that type of information in such an ideal manner of writing? I have a presentation next week, and I’m on the look for such information.
Some really choice blog posts on this site, saved to my bookmarks.