2017ACM暑期多校联合训练 - Team 7 1010 HDU 6129 Just do it (找规律)
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≤2^30−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
题意:
给定一个数组a,然后要求出数组b,数组b于数组a之间满足这样的规律:
b[i]=a[1]a[2]·····^a[i].
像这样的话其实是很简单的,但是我们并不是要求第一次异或得出的数组b,而是要求经过m次异或之后得出的数组b。
分析:
首先找一下规律:(都与最原始的a数组进行比较)
异或第一次的时候:
每一项相当于都把它前面的任意的一项全部都异或上了。
然后再观察异或第二次的时候:
相当于每一项都是差项异或,异或上前面所有的中与它本身相差两项、四项、六项、八项····等等。
异或第三次的时候:
相当于每一项都是差项异或,异或上前面所有的中与它本身相差一项、四项、五项、八项····等等。
然后总结下规律就是:
把每次变换的系数记录下来后可以发现是个杨辉三角,第x次变换第y项是C(x+y-2,y-1);
C(n,m),如果n&m==m则C(n,m)为奇数,考虑第一项对后面每一项的贡献是奇数还是偶数,
依次类推后面的项数产生的贡献情况
代码:
#include <iostream>
#include <cstdio>
#include<string.h>
using namespace std;
const int N = 2e6+10;
int a[N], b[N];
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=1; i<=n; i++)
{
scanf("%d", &a[i]);
}
for(int i=1; i<=n; i++)///第m次异或第i项的时候
{
int nn=m+i-2,mm=i-1;
if((nn&mm)==mm)
{
for(int j=i; j<=n; j++) b[j]^=a[j-i+1];
}
}
for(int i=1; i<=n; i++) printf("%d%c",b[i],i==n?'\n':' ');
}
return 0;
}
2017ACM暑期多校联合训练 - Team 7 1010 HDU 6129 Just do it (找规律)的更多相关文章
- 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)
题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...
- 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)
题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...
- 2017ACM暑期多校联合训练 - Team 6 1010 HDU 6105 Gameia (博弈)
题目链接 Problem Description Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes ...
- 2017ACM暑期多校联合训练 - Team 2 1011 HDU 6055 Regular polygon (数学规律)
题目链接 **Problem Description On a two-dimensional plane, give you n integer points. Your task is to fi ...
- 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)
题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...
- 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)
题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...
- 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)
题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
- 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...
随机推荐
- 1029对c语言文法的理解
<程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...
- 【week8】psp~~进度条
本周psp 项目 内容 开始时间 结束时间 中断时间 净时间 10月7日 星期一 论文 看生物信息方面的论文 10:00 12:00 5 115 写代码 注册信息从前台传入servlet 18:00 ...
- 有一个集合,判断集合里有没有“world”这个元素,如果有,添加“javaee”
// 有一个集合,判断集合里有没有“world”这个元素,如果有,添加“javaee” List list = new ArrayList(); list.add("world") ...
- 【经典数据结构】Trie
在计算机科学中,trie,又称前缀树或字典树,是一种有种树,用于保存关联数组,其中的键通常是字符串.与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定.一个节点的所有子孙都有相同的前 ...
- 使用JMeter代理录制app测试脚本
准备条件:JMeter.手机app 上一篇介绍过录制Web测试脚本的方式有两种,使用代理和使用第三方工具.本篇录制app测试脚本只讨论使用代理的方式,其他方式以后有机会再补充.其实Web和app使用代 ...
- node web 应用热更新
在每次更改完 node.js 项目后,我们都需要先将 node.js停止(快捷键: Ctrl+C),然后再通过命令再次运行,这样特别麻烦.这里我推荐使用 supervisor工具, npm 安装命令为 ...
- window上安装elasticserach
提供一个百度云链接下载elasticsearch (链接:https://pan.baidu.com/s/1sk8PYjV 密码:l586) 测试达到目的:安装elasticsearch后再安装hea ...
- 【EF】EntityFramework DBFirst的使用
一.前言 久闻EF大名,之前做C/S产品用的是Dapper对SqlLite进行ORM.然后接触公司授权系统后发现用的是EntityFramework对SQLSever进行ORM.授权系统 ...
- NOI2018前的每日记录
NOI2018前的每日记录 开头 今天是\(2018.7.2\),不知不觉已经这么久了.本来还是高一的小蒟蒻,过不了多久就要成为高二的老年选手了. 再过半个月我也要去\(NOI\)打酱油了.我这种D类 ...
- 【BZOJ1565】【NOI2009】植物大战僵尸(网络流)
[BZOJ1565][NOI2009]植物大战僵尸(网络流) 题面 BZOJ 洛谷 题解 做了这么多神仙题,终于有一道能够凭借自己智商能够想出来的题目了.... 好感动. 这就是一个比较裸的最小割模型 ...