HDU 6129 Just do it(找规律+杨辉三角)
来源:互联网 发布:超人电力工程预算软件 编辑:程序博客网 时间:2024/05/16 11:24
Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 388 Accepted Submission(s): 218
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 integersn,m(1≤n≤2×105,1≤m≤109) .
The second line containsn nonnegative integers a1...n(0≤ai≤230−1) .
For each test case:
The first line contains two positive integers
The second line contains
Output
For each test case:
A single line containsn nonnegative integers, denoting the final sequence.
A single line contains
Sample Input
21 113 31 2 3
Sample Output
11 3 1
题意:对一个非负整数序列a1-an进行异或操作获得新的序列,操作如下bi=a1^a2…^ai,然后ai=bi,求进行m次后的序列a
思路:我们可得到b[i]=b[i-1]^a[i]而a[i]就是上一次异或得到的b[i],那么其实对于原序列中的第x元素在异或操作中被重复异或的次数所构成的系数为杨辉三角,打表如下
斜着看系数,系数构成的是一个杨辉三角,那么对于a1在第m次对bi的贡献就是i:C(m+i-2,i-1),再根据异或的性质当系数为偶数时相互抵消异或结果为0,系数为奇数时才会有贡献,再根据组合数奇偶的判断方法对于C(n,k),若n&k == k 则c(n,k)为奇数,否则为偶数。对于a2的贡献,只是在a1的情况向后推一位,如a1在m=2,3号位的贡献是奇数那么a2就是在相同情况下的4号位贡献为奇数,a3就是在5号这样推下去
#include <iostream>#include <cstdio>#include <cstring>#include <stdio.h>#include <stdlib.h>#include <algorithm>#include <math.h>using namespace std;const int maxn=200005;int a[maxn],b[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]); memset(b,0,sizeof(b)); for(int i=1;i<=n;i++) { int nn=m+i-2,k=i-1; if((nn&k)==k) for(int j=i;j<=n;j++) b[j]^=a[j-i+1];//a1有j有贡献,那么a2就在j+1有贡献 } for(int i=1;i<=n;i++) i!=n?printf("%d ",b[i]):printf("%d\n",b[i]); } return 0;}
阅读全文
0 0
- HDU 6129 Just do it(找规律+杨辉三角)
- Hdu 6129 Just do it【杨辉三角、规律】
- HDU 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(规律)
- hdu 6129 Just do it -规律
- HDU 6129(找规律+杨辉三角)
- HDU6129 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
- hdu6129 Just do it 2017多校第七场1010 杨辉三角+规律
- jQuery ajax getjson demo
- SAMBA(下)
- 笔记8——Linux系统定时任务
- PHP基础之流程控制
- 前端代码规范
- HDU 6129 Just do it(找规律+杨辉三角)
- socket中recv() send() read() write()区别
- 二分图匹配 --- 最小点覆盖
- jdbc核心之事务
- thinkphp5学习笔记
- 2017.08.15工作日记
- hdu 6124 Euler theorem(水题)
- 4.高性能MySQL --- 服务器性能剖析( 2 )
- 排序--直接插入排序