HDU 6129 Just do it(规律)
2017-08-21 14:50
666 查看
Just do it
HDU 6129 (规律) 2017ACM暑期多校联合训练 - Team 7 1010 Just do it题目链接
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1234 Accepted Submission(s): 724
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×10^5,1≤m≤10^9).
The second line contains n nonnegative integers a1…n(0≤ai≤2^30−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
1
1 3 1
题意:
给定一个数组a,然后要求出数组b,数组b于数组a之间满足这样的规律:
b[i]=a[1]^a[2]^·····^a[i].
像这样的话其实是很简单的,但是我们并不是要求第一次异或得出的数组b,而是要求经过m次异或之后得出的数组b。
分析:
ans[i][j]数组进行异或
你会发现 ans【i】【j】=ans【i-1】【j】^ans【i】【j-1】;
有木有发现杨辉三角形的痕迹。
对于每一项,他的系数就是杨辉三角的值,那么如果当前位子系数为奇数的话,结果就会有贡献(x=x^y^y).
同样很显然,我们第i行,第j列的答案,其系数为C(i+j-2,j-1)【此时只考虑a的系数】
#include <iostream> #include <cstdio> #include<string.h> using namespace std; const int N = 2e6+10; int a , b ; int main() { int t; scanf("%d", &t); while(t--) { int n, m; scanf("%d %d", &n, &m); memset(b,0,sizeof(b)); for(int i=1; i<=n; i++) { scanf("%d", &a[i]); b6d8 } for(int i=1; i<=n; i++)///第m次异或第i项的时候 { int nn=m+i-2,mm=i-1; if((nn&mm)==mm) { for(int j=i; j<=n; j++) b[j]^=a[j-i+1]; } } for(int i=1; i<=n; i++) printf("%d%c",b[i],i==n?'\n':' '); } return 0; }
相关文章推荐
- 【(好题)组合数+Lucas定理+公式递推(lowbit+滚动数组)+打表找规律】2017多校训练七 HDU 6129 Just do it
- (hdu 6129)Just do it(数位异或/规律)
- 解题报告:HDU_6129 Just do it (找规律 两种做法)
- Hdu 6129 Just do it【杨辉三角、规律】
- 2017多校第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 - 2017 Multi-University Training Contest - Team 7(规律、杨辉三角、组合数奇偶性)
- hdu 6129 Just do it (规律递推)
- HDU 6129 Just do it(找规律+杨辉三角)
- HDU 6129 Just do it(多校7, 组合数 规律)
- hdu 6129 Just do it -规律
- hdu 6129 Just do it (找规律)
- HDU 6129 Just do it
- (2017多校训练第七场)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】& 数学推导