CSU1977: Bit-reversal Permutation
来源:互联网 发布:chrome的json插件 编辑:程序博客网 时间:2024/06/05 17:12
CSU1977: Bit-reversal Permutation
Description
A fast Fourier transform (FFT) algorithm computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IFFT). Fourier analysis converts a signal from its original domain (often time or space) to a representation in the frequency domain and vice versa. An FFT rapidly computes such transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the complexity of computing the DFT from O(n2), which arises if one simply applies the definition of DFT, to O(nlogn), where n is the data size. ——From WikipediaDuring this summer holiday, csuxushu feels so bored to learn FFT. Because FFT is a complicated algorithm, he need to apply a bit-reversal permutation to a sequence first before DFT which is a part of FFT.In applied mathematics, a bit-reversal permutation is a permutation of a sequence of n items, where n = 2^k is a power of two. It is defined by indexing the elements of the sequence by the numbers from 0 to n − 1 and then reversing the binary representations of each of these numbers (padded so that each of these binary numbers has length exactly k). Each item is then mapped to the new position given by this reversed value.Because all fellows in CSU(California State University ) can apply FFT, NTT or even FWT, it is a shame that he even doesn't know how to take the first step. As one of the best computer programmer in CSU, can you help him?You may think this problem is too hard to solve. In fact, it is a piece of cake to you. Remember to see the hint :-)InputThe first line of the input gives the number of test cases T(T≤10); T test cases follow.Each test case contains a number sequence.In each case, the first line is a number N(1≤N≤10^5), the number of elements in the following sequence.The second line is the sequence.Its length may not be exactly a power of two, so you can append some zeros to make it the minimal power of two larger than or equal to N.
Output
For each test case, output the sequence from input in bit-reversal order.
Sample Input
1621 58 96 12 45 65
Sample Output
21 45 96 0 58 65 12 0
Hint
Bit-reverse Order中文提示:可以看到,我们最终处理的系数从左至右的编号的二进制形式分别为000,100,010,110,001,101,011,111,若将其二进制反序,可得000,001,010,011,100,101,110,111,这些反序的二进制编码是从小到大排列的。也就是说,我们可以按照每个下标的二进制编码来确定处理系数的顺序。这种方法就称为位逆序置换(Bit-reversal permutation)。
Source
2017年8月月赛
Author
徐戍
比赛中将问题想复杂了,好久也没搞出来。实际上直接按照先0后1的次序,递归地生成顺序序列的二进制数码,同时逆序地计算出这些数码对应的十进制数,直接取出数组中元素就行了。比如我们生成的是
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 1e5+10;int sample[maxn*10];int T, n, k;void dfs(int kk, int index){ if(kk == 0){ // 已产生k位二进制数,并已经知道了它们逆序后对应的十进制数。 if(index == (1<<k)-1) // 不论如何做位逆序置换,最后一个输出的一定是二进制全为1的数。输出它后换行。 printf("%d\n", sample[index]); else // 否则输出后空格。 printf("%d ", sample[index]); return; } dfs(kk-1, index+0); // 递归调用的同时进行逆序进制转换。 dfs(kk-1, index+(1<<(k-kk)));}int main(){#ifdef TESTfreopen("test.txt", "r", stdin);#endif // TEST cin >> T; while(T--){ memset(sample, 0, sizeof(sample)); scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%d", &sample[i]); } k = 0; while(1<<k < n) k++; // 求出令2^k不小于n的最小k值。 dfs(k, 0); } return 0;}/********************************************************************** Problem: 1977 User: xyJiang Language: C++ Result: AC Time:400 ms Memory:5924 kb**********************************************************************/
阅读全文
0 0
- CSU1977: Bit-reversal Permutation
- CSU1977-Bit-reversal Permutation-模拟
- Bit-reversal permutation
- Bit Reversal and Permutation
- 1977:Bit-reversal Permutation
- COJ1977-Bit-reversal Permutation
- 1977: Bit-reversal Permutation(递归)
- CSU 1977: Bit-reversal Permutation
- EPI 5.3 BIT REVERSAL
- Word Reversal
- ZOJ_1151_Word Reversal
- Word Reversal
- Word Reversal
- Word Reversal
- Word Reversal
- Word Reversal
- Happy Reversal
- HUST1339-Reversal
- Retrofit运行方式详解版
- 基数排序
- CC2530基础实验(1)—LED灯闪烁
- size_t 与 ssize_t 类型
- 用Socket 写多人聊天室
- CSU1977: Bit-reversal Permutation
- iOS开发 关键字的区别
- Unity3D利用Photon实现实时联网对战(三)创建和加入房间
- 模拟模拟交易系统(二)——系统设计
- FTPrep, Combination Sum II
- S905方案定制 S805方案定制 Amlogic S805 S905方案设计 MXQ方案 MXQ PRO方案 amlogic方案
- hadoop—视频笔记
- 获取个人AC的题目代码
- jQuery选择器(2)