HDU - 6129 :Just do it (杨辉三角)
InputThe first line contains a positive integer T(1≤T≤5) 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 ) n,m(1≤n≤2×105,1≤m≤109)
.
The second line contains n n
nonnegative integers a 1...n (0≤a i ≤2 30 −1) a1...n(0≤ai≤230−1)
.
OutputFor each test case:
A single line contains n n
nonnegative integers, denoting the final sequence.Sample Input
2
1 1
1
3 3
1 2 3
Sample Output
1
1 3 1
题意:给定a数组,现在有a数组可以转化为b数组,bi=a1^a2^..ai,即b为a数组的异或前缀和;求进行M次后b数组。
思路:暴力每个数对每个位置的贡献:现考虑a[1]对b[i]的贡献,如果是偶数是贡献则可以忽略,而奇数的情况是(i+M-2)&(i-1)==(i-1)(根据杨辉三角)。
如果a[1]对b[i]有贡献,那a[2]对b[i+1],a[3]对b[i+2]...也有贡献,暴力累计即可。
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int a[maxn],b[maxn];
int main()
{
int T,N,M;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&M);
rep(i,,N) scanf("%d",&a[i]),b[i]=;
rep(i,,N){
int x=i+M-,y=i-;
if((x&y)==y)
rep(j,i,N) b[j]^=a[j-i+];
}
rep(i,,N-) printf("%d ",b[i]);
printf("%d\n",b[N]);
}
return ;
}
HDU - 6129 :Just do it (杨辉三角)的更多相关文章
- 2014多校第六场 1007 || HDU 4927 Series 1(杨辉三角组合数)
题目链接 题意 : n个数,每操作一次就变成n-1个数,最后变成一个数,输出这个数,操作是指后一个数减前一个数得到的数写下来. 思路 : 找出几个数,算得时候先不要算出来,用式子代替,例如: 1 2 ...
- hdu 2032 一维数组实现杨辉三角
杨辉三角 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)
233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...
- HDU 6129 Just do it(杨辉三角)
http://acm.hdu.edu.cn/showproblem.php?pid=6129 题意: 给出数组a,并且bi=a1^a2^a3...^ai,并且现在会重复m次,求出最后的b数组. 思路: ...
- HDU 2032 杨辉三角
http://acm.hdu.edu.cn/showproblem.php?pid=2032 Problem Description 还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考 ...
- HDOJ(HDU) 1799 循环多少次?(另类杨辉三角)
Problem Description 我们知道,在编程中,我们时常需要考虑到时间复杂度,特别是对于循环的部分.例如, 如果代码中出现 for(i=1;i<=n;i++) OP ; 那么做了n次 ...
- hdu 5698(杨辉三角的性质+逆元)
---恢复内容开始--- 瞬间移动 Accepts: 1018 Submissions: 3620 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...
- HDU 5794 A Simple Chess(杨辉三角+容斥原理+Lucas定理)
题目链接 A Simple Chess 打表发现这其实是一个杨辉三角…… 然后发现很多格子上方案数都是0 对于那写可能可以到达的点(先不考虑障碍点),我们先叫做有效的点 对于那些障碍,如果不在有效点上 ...
- <hdu-2032>杨辉三角
这是杭电hdu上杨辉三角的链接:http://acm.hdu.edu.cn/showproblem.php?pid=2032 Problem Description: 还记得中学时候学过的杨辉三角吗 ...
随机推荐
- OpenCL 学习step by step (5) 使用二维NDRange workgroup
http://www.cnblogs.com/mikewolf2002/archive/2012/09/07/2675634.html 在本教程中,我们使用二维NDRange来设置workgroup, ...
- contain与compareDocumentPosition
contain方法由IE创建,用于判断元素之间是否是父亲与后代的关系,例如:如果A元素包含B元素,则返回true,否则,返回false eg: <div id= "a"> ...
- LeetCode——single-number系列
LeetCode--single-number系列 Question 1 Given an array of integers, every element appears twice except ...
- UVA 10214 Trees in a Wood(欧拉函数)
题意:给你a.b(a<=2000,b<=2000000),问你从原点可以看到范围在(-a<=x<=a,-b<=y<=b)内整数点的个数 题解:首先只需要计算第一象限 ...
- ThinkPHP关于模板的一些嵌套、IF判断使用
> ##### 前言,现在有一组数据(涉及到3个数据表,order订单表,order_process办理流程表,process_status流程描述表),根据当前订单,展示相应信息 1.办理流程 ...
- 使用Xcode IDE写node.js
最近在玩node.js 但是发现很多IDE就是用不顺手 后来发现Xcode可以剖析java script 于是试着使用Xcode来当做node.js的编辑器 首先,在Mac上必须先安装node.js的 ...
- Elasticsearch 配置优化
cluster.routing.allocation.same_shard.host:true 这会防止同一个shard的主副本存在同一个物理机上(因为如果存在一个机器上,副本的高可用性就没有了). ...
- 《Computational Statistics with Matlab》硬译2
T=; sigma=; thetamin=-;thetamax=; theta=zeros(,T); seed=;rand('state',seed);randn('state',seed); the ...
- java中的Properties
Properties类继承自HashTable类并实现了Map接口,也是使用一种键值对的形式来保存属性集.不过Properties有特殊的地方,就是它的键和值都是字符串类型. Properties中的 ...
- SpringBoot:竟然has no explicit mapping for /error
异常:This application has no explicit mapping for /error, so you are seeing this as a fallback. 出现这个异常 ...