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 ...
随机推荐
- 1st 四人小组项目
小组名称:好好学习 项目组长:林莉 组员:王东涵.宫丽君.胡丽娜 项目选题:基于jsp的车库管理系统 项目期限:十周内<暂定> 需求分析:有待进一步思考
- JSON和Django内置序列化
JSON 什么是JSON JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式 JSON 独立于语言 * J ...
- eclipse官方网址、各个版本的下载
Eclipse3.1后各版本代号 (2013-07-10 20:48:42) 转载▼ 分类: Java Eclipse 3.1 版本代号 IO [木卫1,伊奥] Eclipse 3.2 版本代号 ...
- 第73天:jQuery基本动画总结
一.DOM对象跟jQuery对象相互转换 jQuery对象转换成DOM对象: 方式一:$(“#btn”)[0] 方式二:$(“#btn”).get(0) DOM对象转换成jQuery对象: $(doc ...
- bzoj1061-[Noi2008]志愿者招募-单纯形 & 费用流
有\(n\)天,\(m\)类志愿者,一个第\(i\)类志愿者可以从第\(s_i\)天工作到第\(t_i\)天,第\(i\)天工作的志愿者不少于\(b_i\)个.每一类志愿者都有单价\(c_i\),问满 ...
- 使用Appium上传/下载文件(push文件、pull文件)
package com.lx.class1; import java.io.File; import java.io.IOException; import java.net.URL; import ...
- Liunx 和 Win中的软链接详解
用过Linux的朋友都知道linux中有软链接的概念,可以通过ln命令创建到目录或文件的软链接,软链接的好处就是可以让一个目录或文件有多个入口但保持单一物理位置,方便应用和管理. 1.命令格式: ...
- Spring Boot系列教程二:创建第一个web工程 hello world
一.创建工程 创建名称为"springboot_helloworld"的spring boot工程, new->Spring Starter Project,直接上图 ...
- URAL1519:Formula 1——题解
http://acm.timus.ru/problem.aspx?space=1&num=1519 https://vjudge.net/problem/URAL-1519 题目大意:给一个网 ...
- Unity3D for VR 学习(9): Unity Shader 光照模型 (illumination model)
关于光照模型 所谓模型,一般是由学术算法发起, 经过大量实际数据验证而成的可靠公式 现在还记得2009年做TD-SCDMA移动通信算法的时候,曾经看过自由空间传播模型(Free space propa ...