HDU 6129 just do it(组合数奇偶性)

Just do it点击打开链接

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1411    Accepted Submission(s): 823


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(1T5), denoting the number of test cases.
For each test case:
The first line contains two positive integers n,m(1n2×105,1m109).
The second line contains n nonnegative integers a1...n(0ai2301).
 

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
 

Source
2017 Multi-University Training Contest - Team 7 
【分析】:

组合数C(n,m)的奇偶性:讲解:http://blog.csdn.net/millky/article/details/3206730

if((n&m)==m) 奇数

else     偶数

m次操作之后,只需计算每个元素对后面元素的贡献。

若贡献为偶数次,由于是亦或,可忽略

若贡献为奇数次,那么只需亦或一次。

试着写了写m=1,2,3,4,....的时候,得出规律:

第一个元素对第i个元素的贡献次数为C(i+m-2,m-1)我们只用到他的奇偶性。

【代码】:

#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
int a[202020],b[202020];
int e[202020];
int T,n;
ll h;
int main()
{
    cin>>T;
    while(T--)
    {
        cin>>n>>h;
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int top=0;
        ll x=h-1,y=h-1;
        for(int i=1;i<=n;i++,x++)
        {
            if((x&y)==y)e[top++]=i;//i点组合数为奇数
        }
        memset(b,0,sizeof(b));
        for(int i=1;i<=n;i++)
        {
            for(int j=0; i+e[j]-1<=n&&j

你可能感兴趣的:(ACM**数论*******,ACM算法题解)