HDU 6129 Just do it(多校7, 组合数 规律)

78 篇文章 0 订阅

题意:

给你一个数列, m次变换, 每次变换b[i] = a[1]~a[i]的异或值。 求最后的序列。

思路:

一个找规律的题目。

考虑 每一个数对后面的数的贡献。

先考虑a1:

第一次变换: 1 1 1 1 1

第二次变换: 1 2 3 4 5

第三次变换: 1 3 6 10 15

第四次变换: 1 4 10 20 35

不难发现 每一行是 杨辉三角的斜边。

所以 f(x,y) = C(x+y-2,y-1)  其中f(x,y)表示变换x次, a1 对第y 个位置数的贡献值。

那么只考虑 这个组合数是奇数还是偶数即可。

有个简单的公式  C(x,y) 是奇数当且仅当 (x & y) == y 的时候满足。

然后在考虑怎么把所有贡献算出来, 因为我们算的是a1的贡献, a2,a3,a4 的贡献相当于从a1的位置向右挪了挪, 在挪回来即可。

所以我们枚举a1的贡献值,当是奇数的时候,我们在计算后面的贡献。

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

const int maxn = 200000 + 10;
int a[maxn], ans[maxn];
int main(){

    int T;
    scanf("%d",&T);
    while(T--){
        int n, m;
        scanf("%d %d",&n, &m);
        for (int i = 1; i <= n; ++i){
            scanf("%d",a+i);
            ans[i] = 0;
        }


        for (int i = 1; i <= n; ++i){
            int x = i + m - 2;
            int y = i-1;
            if ((x&y)==y){
                for (int j = i; j <= n; ++j){
                    ans[j] ^= a[j-i+1];

                }


            }


        }
        for (int i = 1; i <= n; ++i){
            if (i > 1)putchar(' ');
            printf("%d", ans[i]);
        }
        putchar('\n');
    }

    return 0;
}


Just do it

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


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
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6132  6131  6130  6129  6128 
 

Statistic |  Submit |  Discuss |  Note

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值