zoukankan      html  css  js  c++  java
  • HDU 6129 Just do it(规律)

    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[N], b[N];
    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]);
            }
            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?'
    ':' ');
        }
        return 0;
    }
  • 相关阅读:
    python enhanced generator - coroutine
    python yield generator 详解
    gunicorn syncworker 源码解析
    gunicorn 信号处理(SIGHUP,SIGUSR2)
    gunicorn Arbiter 源码解析
    gunicorn 简介
    kafka+zookeeper环境配置(linux环境单机版)
    在Linux中安装JDK的步骤
    Kafka安装及部署
    Zookeeper 安装和配置
  • 原文地址:https://www.cnblogs.com/nanfenggu/p/7900043.html
Copyright © 2011-2022 走看看