Derivation of formula + Yang Hui's triangle + xor or property + feed representation XOR Matrix hackerrank-xor-matrix__ formula derivation

Source: Internet
Author: User
Tags first row

Do you:
1 Knowledge Points: "Formula derivation + Yang Hui's triangle + xor or character + feed representation"
2:
Define XOR or matrix elements a[i, J]:

The first line enters N, M represents the Xor of N row m columns, and the second row enters n elements to represent the first row of the XOR or matrix, and the title asks us to output the row of the XOR or matrix.
2.1 Data range:
·1 <= N <= 1e5
·1 <= m <= 1e18
·1 <= A[i, j] <= 1e9
3 Problem Solving Process
3.1 Formula derivation:
A[i, j] = A[i-1, j] ^ a[i-1, j+1]
That is, for A[i, J] a single element:
A[0, j] = A[0, j]
A[1, j] = A[0, j] ^ a[0, j+1]
A[2, j] = A[1, j] ^ a[1, j+1] = (a[0, j] ^ a[0, j+1]) ^ (a[0, j+1] ^ a[0, j+2])
= A[0, j] ^ a[0, j+1] ^ a[0, j+1] ^ a[0, j+2]
A[3, j] = A[2, j] ^ a[2, j+1] = (.) ^ (.)
= A[0, j] ^ a[0, j+1] ^ a[0, j+1] ^ a[0, j+1] ^ a[0, j+2] ^ a[0, j+2] ^ a[0, j+2] ^ a[0, j+3]
.
.
.
That
A[i, J]⇦a[0, J], A[0, j+1], a[0, j+2] , A[0, J+i]
And then push it:
A[x+i, J]⇦a[x, J], A[x, j+1], a[x, j+2] , A[x, J+i]

3.2 Yang Hui's triangle
Will A[i, j] by A[0, J], A[0, j+1], a[0, j+2], , A[0, J+i] indicates that the discovery coefficient satisfies the Yang Hui's triangle:

3.3 Different or property
A[i, J] ^ a[i, j] = 0
A[i, j] ^ 0 = a[i, j]
A[i by Xor, J] ^ a[i, j] = 0 and A[i, j] ^ 0 = 0 Degenerate coefficient matrix
The new coefficient matrix is:
0.1
1.1 1
2.1 0 1
3.1 1 1 1
4.1 0 0 0 1
5.1 1 0 0 1 1
6.1 0 1 0 1 0 1
7.1 1 1 1 1 1 1 1
8.1 0 0 0 0 0 0 0 1
9.1 1 0 0 0 0 0 0 1 1
...
That
A[0, j] = A[0, j]
A[1, j] = A[0, j] + a[0, j+1]
A[2, j] = A[0, j] + a[0, j+2]
A[3, j] = A[0, j] + a[0, j+1] + a[0, j+2] + a[0, j+3]
A[4, j] = A[0, j] + a[0, j+4]
A[5, j] = A[0, j] + a[0, j+1] + a[0, j+4] + a[0, j+5]
A[6, j] = A[0, j] + a[0, j+2] + a[0, j+4] + a[0, j+6]
A[7, j] = A[0, j] + a[0, j+1] + a[0, j+2] + a[0, j+3] + a[0, j+4] + a[0, j+5] + a[0, j+6] + a[0, j+7]
A[8, j] = A[0, j] + a[0, j+8]
A[9, j] = A[0, j] + a[0, j+1] + a[0, j+8] + a[0, j+9]
It can be found that for a row with a power of 2, only through A[0, J] and A[0, J+i] Two two-factor coefficients can be computed a[i, j], namely:

3.4 Binary means:

4. "Recommended Reference" code:

#include <bits/stdc++.h>
using namespace std;

#define N 111111
int a[n];
int b[n];
int n;

void Move (int k) {
    //Compute the 2^k ' th row for
    (int i = 0; i < n; i++) b[i] = A[i] ^ a[(i + (1LL << k)) % n];

    Copy back to ' a ' for
    (int i = 0; i < n; i++) a[i] = B[i];
}
int main () {
    //Take the input
    long long m;
    scanf ("%d%lld", &n, &m);
    for (int i = 0; i < n; i++) scanf ("%lld", &a[i));

    Compute the answers
    m--;
    for (int k = 0; k < a k++) {
        if (M & (1LL << k)) move (k);
    }

    Print the answers
    for (int i = 0; i < n; i++) printf ("%d", A[i]);

Vjudge Topic link

The following is the accepted code

 #include <bits/stdc++.h> using namespace std;
typedef long Long LL;

const int N = 104014;

int n, A[n], b[n];

void Move (int k);
  int main () {LL m;
    while (~scanf ("%d%lld", &n, &m)) {for (int i = 0; i < n; i++) scanf ("%d", &a[i));
    m--;
    for (int k = 0; k </k++) {if (M & (1LL << k)) move (k); for (int i = 0; i < n; i++) printf ("%d%c", a[i], i = = n-1?
  ' \ n ': ');
return 0;

  void Move (int k) {for (int i = 0; i < n; i++) B[i] = a[i]^ (a[(i+ (1ll<<k))%n]);
  for (int i = 0; i < n; i++) a[i] = B[i];
Return }

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.