Given an array, evaluate the minimum K value of these arrays in an exclusive or number.
First, Gaussian deyuan is used to obtain the linear base, and then K is split in binary format.
Note that if there is 0 at the end of the Gaussian elimination element, the value 1st is smaller than 0, and then k --
Then, the HDU output long is % i64d, regardless of C-producer or G-producer.
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 10100using namespace std;typedef long long ll;int n,m,cnt;bool zero;ll a[M];void Gaussian_Elimination(){int i,k=0;ll j;for(j=1ll<<62;j;j>>=1){for(i=k+1;i<=n;i++)if(a[i]&j)break;if(i==n+1)continue;swap(a[i],a[++k]);for(i=1;i<=n;i++)if(i!=k)if(a[i]&j)a[i]^=a[k];}zero=(k!=n);n=k;}ll Query(ll x){int i;ll re=0;x-=zero;if(!x)return 0;for(i=n;i;i--){if(x&1)re^=a[i];x>>=1;}if(x)return -1;return re;}int main(){int T,i;ll x;for(cin>>T;T;T--){printf("Case #%d:\n",++cnt);cin>>n;for(i=1;i<=n;i++)scanf("%I64d",&a[i]);Gaussian_Elimination();cin>>m;for(i=1;i<=m;i++)scanf("%I64d",&x),printf("%I64d\n", Query(x) );}}
HDU 3949 XOR Gaussian elimination