HDU 6129 Just do it【杨辉三角】
来源:互联网 发布:scada数据采集 编辑:程序博客网 时间:2024/05/18 18:16
题目来戳呀
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×105,1≤m≤109).
The second line contains n nonnegative integers a1…n(0≤ai≤230−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
Source
2017 Multi-University Training Contest - Team 7
题意
给你数组a,求每个数m次异或和之后的数组b。
即 b[i]=a[1]^a[2]^a[3]…^a[i](这里的a[]是指上一次异或之后的a[])
想法
我们写m=5,n=5的来看一看
我们单独把某一个的异或次数拿出来看 ,比如a的
发现斜着来看就是杨辉三角!
变化第x次,第y项的系数就是
而又因为在异或关系中,异或自身偶数次结果为0,异或自身奇数次结果还是本身。所以我们只要寻找异或次数为奇数次的就可以。
比如上图m=5,n=5.我们要求第m次一伙的第1项时,算出C(4,0)=1,为奇数都有1这个系数,b[1]~b[5](最终要求的)异或上a[1]~a[5].第二项C(5,1)=5,为奇数,b[2]~b[5]分别异或a[1]~a[4],………….一直按这个规律求下去。
接下来的重点就是怎么判断这个次数的奇偶性。
其实是有这么一个公式的,但是在网上不容易找到/(ㄒoㄒ)/~~
C(n,m),如果n&m==m则C(n,m)为奇数
基本问题就是这些了,慢慢敲代码吧~
#include<bits/stdc++.h>using namespace std;const int maxn=2e5+10;int a[maxn+10],b[maxn+10];int main(){ int t,n,m; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=1; i<=n; ++i) scanf("%d",&a[i]); memset(b,0,sizeof b); for(int i=1; i<=n; ++i) { int x=i+m-2,y=i-1; if((x&y)==y) { for(int j=i; j<=n; ++j) b[j]^=a[j-i+1]; } } for(int i=1; i<=n; ++i) { if(i!=1) printf(" "); printf("%d",b[i]); } printf("\n"); } return 0;}
ps:强迫症画个图简直要气哭TAT
- Hdu 6129 Just do it【杨辉三角、规律】
- HDU 6129 Just do it(找规律+杨辉三角)
- hdu 6129 Just do it(杨辉三角)
- hdu 6129 Just do it (杨辉三角)
- HDU 6129 Just do it【杨辉三角】
- HDU 6129 Just do it【杨辉三角】【思维题】【好题】
- HDU 6129 Just do it【杨辉三角+思维+Lucas定理】
- HDU 6129 Just do it(有点复杂的杨辉三角)
- HDU 6129 Just do it(杨辉三角+lucas \ 记忆化dp)
- 2017杭电多校第七场1010 Just do it(数论,杨辉三角)HDU 6129
- 2017多校联合第七场1010/hdu 6129 Just do it(递推/杨辉三角)
- HDU 6129 Just do it
- HDU 6129 Just do it
- HDU 6129 Just do it
- HDU 6129Just do it
- HDU-6129 Just do it
- hdu 6129 Just do it
- hdu 6129 Just do it
- 高并发解决方案
- 文章标题
- spfa优化
- 2017广东工业大学程序设计竞赛决赛:G. 等凹数字(数位DP)
- HDU1087 Super Jumping! Jumping! Jumping!(dp问题)
- HDU 6129 Just do it【杨辉三角】
- 2017.08.18 利用python打印一年的日历
- 图的基本存储的基本方式二——邻接表(链表)
- heroku 自动部署create-react-app项目
- google books ngram viewer数据集的下载与使用
- OJ中的语言选项里G++ 与 C++的区别
- 带负值的背包问题poj2184
- C++函数重载
- 定时器的实现 Quartz