HDU 6129 Just do it
2017-08-16 09:13
399 查看
Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 439 Accepted Submission(s): 245
Problem Description
There is a nonnegative integer sequence a1...n of
length n.
HazelFan wants to do a type of transformation called prefix-XOR, which means a1...n changes
into b1...n,
where bi equals
to the XOR value of a1,...,ai.
He will repeat it for m times,
please tell him the final sequence.
Input
The first line contains a positive integer T(1≤T≤5),
denoting the number of test cases.
For each test case:
The first line contains two positive integers n,m(1≤n≤2×105,1≤m≤109).
The second line contains n nonnegative
integers a1...n(0≤ai≤230−1).
Output
For each test case:
A single line contains n nonnegative
integers, denoting the final sequence.
Sample Input
2
1 1
1
3 3
1 2 3
Sample Output
2017 Multi-University Training Contest - Team 7
题意:
已知一个A【i】数组,需要求一个B【i】数组
B【i】 = A【1】 ^ A【2】... ^ A【i】
求经过m次XOR运算后,所得到的B【i】数组
题解:
打个表后 发现 1-2位 2次循环 2-4位 4次一循环
5-8位8次一循环
基本规律是看最后一位数字所在的2^k次方的区间
m次XOR过程可以减少,但还是妥妥的TLE
从二进制来考虑的话,发现会出现4次一循环
a[i] = a[i] ^ a[i - cnt]推导可得
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<time.h> #define ll long long using namespace std; int main() { int t,n,m; ll a[200050]; // clock_t start,end; // start = clock(); scanf("%d",&t); while (t--) { scanf("%d%d",&n,&m); for (int i = 1; i <= n; i++) scanf("%lld",&a[i]); int cnt = 1; while ((cnt << 2) <= m) cnt <<= 2; while (m > 0) { while (m >= cnt) { for (int i = cnt + 1; i <= n; i++) a[i] = a[i] ^ a[i - cnt]; m -= cnt; } cnt >>= 2; } printf("%lld",a[1]); for (int i = 2; i <= n; i++) { printf(" %lld",a[i]); } puts(""); } // end = clock(); // printf("time = %d",end - start); return 0; }
相关文章推荐
- hdu 6129 Just do it(杨辉三角)
- hdu 6129 Just do it(递推)
- hdu 6129 Just do it(递推)
- HDU 6129 Just do it
- hdu 6129 Just do it (找规律)
- hdu 6129 Just do it(递推)
- hdu 6129(Just do it)
- HDU 6129 Just do it【杨辉三角】
- HDU 6129 Just do it
- HDU 6129 Just do it(规律)
- HDU - 6129 Just do it 找规律
- hdu 6129 Just do it(找规律)
- hdu 6129 Just do it(递推)
- 【(好题)组合数+Lucas定理+公式递推(lowbit+滚动数组)+打表找规律】2017多校训练七 HDU 6129 Just do it
- 多校7 HDU - 6129 Just do it 组合数学
- HDU 6129 Just do it
- HDU - 6129 Just do it(找规律)
- hdu--6129--Just do it
- HDU 6129 just do it(组合数奇偶性)
- HDU 6129 Just do it(找规律+杨辉三角)