hdu 5244 inverse(分治)

inverse

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 193    Accepted Submission(s): 97

Problem Description

Mike has got a huge array b, and he is told that the array is encrypted.

The array is encrypted as follows.

Let ai(0≤i<n) be the i-th number of this original array.

Let bi(0≤i<n) be the i-th number of this encrypted array.

Let n be a power of 2, which means n=2k.

The bi is calculated as following.

bi=∑0≤j<nf((i or j) xor i)aj

f(x) means, if the number of 1 in the binary of x is even, it will return 1, otherwise 0.

Mike want to inverse the procedure of encryption.

Please help him recover the array a with the array b.

Input

The first line contains an integer T(T≤5), denoting the number of the test cases.

For each test case, the first line contains an integer k(0≤k≤20),
The next line contains n=2k integers, which are bi respectively.

It is guaranteed that, ai is an integer and 0≤ai≤109.

Output

For each test case, output ‘‘Case #t:‘‘ to represent this is the t-th case. And then output the array a.

Sample Input

2
0
233
2
5 3 4 10

Sample Output

Case #1: 233
Case #2: 1 2 3 4

Source

The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest

Recommend

时间: 2024-11-19 18:52:47

hdu 5244 inverse(分治)的相关文章

hdu 5244 inverse (上海大都会赛) (分治算法)

nverse Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 110    Accepted Submission(s): 44 Problem Description Mike has got a huge array b, and he is told that the array is encrypted. The array i

hdu 6128 Inverse of sum(推公式)

题目链接:hdu 6128 Inverse of sum 题意: 给你n个数,问你有多少对i,j,满足i<j,并且1/(ai+aj)=1/ai+1/aj 在%p意义下. 题解: 不愧是高中生,推公式神题. 将式子通分化简后可得(ai2+aj2+ai*aj)%p=0. 然后两边同时将两边乘(ai-aj),化简可得(ai3-aj3)%p=0. 然后就可以用map记录一下个数,并且减掉ai==aj时不合法的情况就行了. 1 #include<bits/stdc++.h> 2 #define F

hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi&#39;an Online)

Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 675    Accepted Submission(s): 237 Problem Description Trader Dogy lives in city S, which consists of n districts. There are n - 1

HDU 5102 树分治

The K-th Distance Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 202    Accepted Submission(s): 50 Problem Description Given a tree, which has n node in total. Define the distance between two

2017多校第7场 HDU 6128 Inverse of sum 推公式或者二次剩余

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6128 题意:给你n个数,问你有多少对i,j,满足i<j,并且1/(ai+aj)=1/ai+1/aj 在%p意义下. 解法:官方题解说是用二次剩余来解,但是我并不会这玩意了.在网上看到一位大佬没有二次剩余直接通过推公式做出了这题,真是神奇.http://www.cnblogs.com/bin-gege/p/7367337.html  将式子通分化简后可得(ai2+aj2+ai*aj)%p=0 .然后两

HDU 5322 Hope (分治NTT优化DP)

题面传送门 题目大意: 假设现在有一个排列,每个数和在它右面第一个比它大的数连一条无向边,会形成很多联通块. 定义一个联通块的权值为:联通块内元素数量的平方. 定义一个排列的权值为:每个联通块的权值之积 求长度为$n$所有排列的权值之和,$n\leq 1e5$,$1e4$组询问 原题面描述不清楚啊..害得我白想了30min 和ZOJ3874一样都是排列$DP$问题 $DP$方程还是不难想的 假设现在有一个$i-1$的排列,当我们把$i$某个位置上时 $i$前面的数都会和$i$连通,$i$后面的数

HDU 4916 树分治

Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 285    Accepted Submission(s): 94 Problem Description Trader Dogy lives in city S, which consists of n districts. There are n - 1

hdu 4868 树分治

#include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<iostream> #include<queue> using namespace std; const int M = 60005; struct Edge{ int v, next, w; }edge[M << 2], ee[M ]; map<int, int

上海邀请赛 补题中

比赛的时候就出了5题,赛后发现其实很多题可以写,不知道为啥赛时这么逗比加坑队友,过两天做个总结 5236 Article 29.45%(134/455) 5237 Base64 41.67%(175/420)   5238 Calculator 43.85%(82/187) 5239 Doom 23.67%(138/583) 5240 Exam 50.61%(249/492) 5241 Friends 48.86%(215/440) 5242 Game 29.91%(195/652) 5243