HDU 6129 just do it(组合数奇偶性)
来源:互联网 发布:如何查看淘宝商品排名 编辑:程序博客网 时间:2024/06/04 23:25
Just do it点击打开链接
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1411 Accepted Submission(s): 823
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
Source
2017 Multi-University Training Contest - Team 7
【分析】:组合数C(n,m)的奇偶性:讲解:http://blog.csdn.net/millky/article/details/3206730
if((n&m)==m) 奇数
else 偶数
m次操作之后,只需计算每个元素对后面元素的贡献。
若贡献为偶数次,由于是亦或,可忽略
若贡献为奇数次,那么只需亦或一次。
试着写了写m=1,2,3,4,....的时候,得出规律:
第一个元素对第i个元素的贡献次数为C(i+m-2,m-1)我们只用到他的奇偶性。
【代码】:
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;int a[202020],b[202020];int e[202020];int T,n;ll h;int main(){ cin>>T; while(T--) { cin>>n>>h; for(int i=1;i<=n;i++) scanf("%d",&a[i]); int top=0; ll x=h-1,y=h-1; for(int i=1;i<=n;i++,x++) { if((x&y)==y)e[top++]=i;//i点组合数为奇数 } memset(b,0,sizeof(b)); for(int i=1;i<=n;i++) { for(int j=0; i+e[j]-1<=n&&j<top; j++) b[i+e[j]-1]^=a[i]; if(i<n) printf("%d ",b[i]); else 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(多校7, 组合数 规律)
- Just do it(HDU 6129)
- 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
- HDU 6129 Just do it
- HDU 6129 Just do it
- hdu--6129--Just do it
- HDU 6129 Just do it
- HDU-Just do it
- HttpClient+HttpURLConnection
- XMMPP实现即时通讯
- LeetCode Partition List
- 二维码扫描
- Myeclipse编码方式
- HDU 6129 just do it(组合数奇偶性)
- FZU 1683 纪念SlingShot
- 关于特征工程入门中的一些基本知识(整理)
- client
- 自定义View之绕着圆圈的箭头~~
- 第二十二课(二)、高级SQL特性
- ButterKnife
- 顺序表应用8:最大子段和之动态规划法
- SDUT 2123 查找练习 hash——出现过的数字