HDU 6129
来源:互联网 发布:办公室网络拓扑图 编辑:程序博客网 时间:2024/05/20 16:01
Just do it
时间限制: 5 Sec 内存限制: 128 MB题目描述
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.
输入
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).
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).
输出
For each test case:
A single line contains n nonnegative integers, denoting the final sequence.
A single line contains n nonnegative integers, denoting the final sequence.
样例输入
21 113 31 2 3
样例输出
11 3 1
题意:
给定一个数组a,然后要求出数组b,数组b于数组a之间满足这样的规律:
b[i]=a[1]^a[2]^·····^a[i].
但是并非求经过一次转换后的b[i],而是经过每次的转换m次后的b[i]
解题思路:如果直接暴力,会超时。
如果我们假设数组a的元素分别为:a bc d;
第一次转换后:a a^b a^b^c a^b^c^d;
第二次转换后:a a^a^ba^a^a^b^b^c a^a^a^a^b^b^b^c^c^d;
若设列为i,行为j很显然,所求位置(i,j)=(i,j-1)+(i-1,j);所以可以发现这是杨辉三角
可以发现第x次变换第y项是C(x+y-2,y-1)
对于C(n,m),如果n&m==m则C(n,m)为奇数。
若为奇数则贡献,若为偶数异或后为零不贡献
以上讨论是考虑第一项(a)对所有位子的结果的影响即可(因为b就相当于向后挪了一下递推即可)
源代码:
#include<iostream>#include<cstdio>#include<cstring>const int M=2e6+1;int a[M],b[M];using namespace std;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=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++)//第m次异或第i项 { int y=i; int x=i+m-1; if((x&y)==y) { for(int j=i;j<n;j++) b[j]^=a[j-i]; } } for(int i=0;i<n;i++) printf("%d%c",b[i],i==n-1?'\n':' '); } return 0;}
阅读全文
0 0
- HDU 6129
- hdu 6129
- HDU 6129
- hdu 6129-推理
- HDU 6129 规律+数论
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- Color argb()方法的参数
- forward 和 redirect 区别
- CodeFroces 817C Really Big Numbers(二分)
- 将lnmp 自带的 php 5.4升级为 5.6
- Centos系统下Docker安装
- HDU 6129
- 莫比乌斯反演总结
- 商城功能构建
- DNS域名解析过程
- Laravel的JsonResponse函数返回后前台处理代码
- c++动态内存传递
- Chrome调试工具developer tool技巧
- Informatica各种对象的关系查询
- Android系统定制——Download Android System 及加载system镜像文件