HDU 3949 XOR Gaussian elimination

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.