zoukankan      html  css  js  c++  java
  • hdu 5142 NPY and FFT

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=5142

    NPY and FFT

    Description

    A boy named NPY is learning FFT algorithm now.In that algorithm,he needs to do an operation called "reverse".
    For example,if the given number is 10.Its binary representaion is 1010.After reversing,the binary number will be 0101.And then we should ignore the leading zero.Then the number we get will be 5,whose binary representaion is 101.
    NPY is very interested in this operation.For every given number,he want to know what number he will get after reversing.Can you help him?

    Input

    The first line contains a integer T — the number of queries $(1 leq T leq 100).$
    The next T lines,each contains a integer $egin{align*}X(0 leq X leq 2^{31}-1)end{align*}$,the given number.

    Output

    For each query,print the reversed number in a separate line.

    Sample Input

    3
    6
    8
    1

    Sample Output

    3
    1
    1

    想用位运算写,结果写不来只好用笨办法写了。。

     1 #include<cstring>
     2 #include<cstdio>
     3 int buf[40];
     4 void go(int n) {
     5     int i, j = 0, res = 0;
     6     memset(buf, 0, sizeof(buf));
     7     do buf[j++] = n & 1; while (n >>= 1);
     8     for (i = j - 1; ~i; i--) res += buf[i] * (1 << (j - i - 1));
     9     printf("%d
    ", res);
    10 }
    11 int main() {
    12     int t, n;
    13     scanf("%d", &t);
    14     while (t--) scanf("%d", &n), go(n);
    15     return 0;
    16 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    ubuntu16.04以及各个版本镜像网址汇总
    linux0.11的进程1的创建和执行
    linux0.11的0号进程详解
    Linux命令
    Vim命令
    CentOS7静态IP设置
    Fiddler常用设置
    Python日期计算
    Python完全平方数
    pip
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4561594.html
Copyright © 2011-2022 走看看