hdu6129Just do it(递推规律)

Just do it

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


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
找出前缀异或m次形成的新序列b
这道题昨晚都不知道为毛有这种规律。。。。

1   2   3   第一次形成:1 3 0,第二次  : 1 2 2  第三次: 1  3  1
 假如是1,2,3,4,可以先打表找出规律
for(int i=1;i<=100;i++)
{a1=a1; 
a2^=a1;
a3^=a2;
a4^=a3;
a5^=a4;
printf("%d %d %d %d %d\n",a1,a2,a3,a4,a5);
}

题解中给出新的序列的系数值为杨辉三角的规律,也就是当前值等于上一次的递推值*前一个的当前值,用数组来讲就是dp[i][j]=dp[i-1][j]*dp[i][j-1];
这样在x&y==y时,也就是系数为奇数时能确定其价值
/**
   by z_guibin
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
#define N 200500
int a[N],b[N];
int main()
{
    /*int a1=1,a2=2,a3=3,a4=4,a5=5;
    int s[100];
    for(int i=1;i<=100;i++)
    {
        a1=a1;
        a2^=a1;
        a3^=a2;
        a4^=a3;
        a5^=a4;
        printf("%d %d %d %d %d\n",a1,a2,a3,a4,a5);
    }*/
    
    int t;
    int n,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        memset(b,0,sizeof(b));
        for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
        for(int i=0;i<n;i++)
        {
            int x=i+m-1;
            int y=i;
            if((x&y)==y)
            {
                for(int j=i;j<n;j++)
                {
                    b[j]^=a[j-i];
                }
            }
        }
        for(int i=0;i<n-1;i++)
        {
            printf("%d ",b[i]);
        }
        cout<<b[n-1]<<endl;
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值