HDU 3949 or linear base __ or linear base

Source: Internet
Author: User

Topic link

Meaning
There are n numbers and q Q, and each query gives a positive integer k K, asking what number of K K is small in all numbers of n n numbers or combinations, and if not, output −1-1.

Ideas:
First, the N-n number of the different or linear base is constructed.

Assuming that non 0 linear bases have a total of tot tot, the results of the first 1− (x−1) n (x-1) linear group, regardless of linear combination, are less than the X-X linear basis for the X-X linear basis.

Because the X-X linear base assumes that the highest bit of 1 1 is in K K, because a carry is different or not, it is not possible to combine a small base with a bits greater than or equal to K K of 1 1.

In this case, the linear combination of the linear basis of the size of the order is very similar to the binary size of the order, such as:
10000 100,001 is larger than the 01111,01101,01110 01111,01101,01110, such as the 0xxxx 0xxxx binary number.

Therefore, the K-K binary decomposition can be considered, and if the first I is 1, then the contribution of the linear base from small to large sorted.

Therefore, for TOT tot linear basis, the case of linear combination has 2tot−1 2^{tot}-1 species altogether.
But this does not include 0 0.

So you can give a special sentence, if n n vectors are all used to form a linear basis, there will be no differences or 0 0.

So the problem is solved.

Code:

#include <cstdio> #include <cstring> #include <algorithm> using namespace std;

typedef long Long LL;
const int A = 1e4 + 10;
ll A[a],b[110],c[a];

int N,zero,tot;
    void Init () {zero = tot = 0;
    Memset (b,0,sizeof (b)); for (int i=1; i<=n i++) for (int j=62; j>=0; j--) {if (a[i]>>j) &1) {if (b[j)) A[i] ^= b[
            J];
                else{B[j] = a[i];tot++;
                for (int k=j-1; k>=0 k--) if (B[k] && ((b[j]>>k) &1)) B[j] ^= b[k];
                for (int k=j+1; k<=62;k++) if ((b[k]>>j) &1) b[k] ^= b[j];
            Break
    }} zero = (tot<n); tot = 0;
for (int i=0; i<=62 i++) if (b[i)) c[tot++] = B[i];
    ll solve (ll K) {if (zero) k--;
    if (k >= (1ll<<tot)) return-1;
    ll ans = 0;
    for (int i=0; i<=62 i++) if ((k>>i) &1) ans ^= c[i];
return ans;
    int main () {int t,_=1;scanf ("%d", &t); WhilE (t--) {scanf ("%d", &n);
        for (int i=1; i<=n i++) scanf ("%i64d", &a[i));
        Init ();
        int q;scanf ("%d", &q);
        printf ("Case #%d:\n", _++);
            while (q--) {ll k;scanf ("%i64d", &k); printf

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.