zoukankan      html  css  js  c++  java
  • hdu 5142(数学-进制转换)

    NPY and FFT

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 799    Accepted Submission(s): 492


    Problem 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 (1T100).
    The next T lines,each contains a integer X(0X2311),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
     
    Source
     
    题意:把一个数字换成二进制,然后将其二进制倒过来得到的新的数的十进制是多少?
    题解:直接模拟这个过程.
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include <queue>
    using namespace std;
    
    int main()
    {
        int tcase;
        scanf("%d",&tcase);
        while(tcase--){
            int n;
            scanf("%d",&n);
            int a[100];
            int id=0;
            while(n){
                a[id++] = n%2;
                n/=2;
            }
            int k=0,flag=0;
            for(int i=0;i<id;i++){
                if(a[i]!=0) flag = true;
                if(flag) a[k++] = a[i];
            }
            int ans = 0;
            for(int i=k-1;i>=0;i--){
                int temp = 1;
                for(int j=0;j<k-1-i;j++) temp*=2;
                ans+=temp*a[i];
            }
            printf("%d
    ",ans);
        }
    }
  • 相关阅读:
    Java 字节码解释说明
    JVM垃圾回收:G1回收器
    JVM 参数
    HotSpot 虚拟机对象探秘
    JDK 内置图形界面工具
    Java 内存模型
    在网络设备上调试 Android 程序
    .NET MVC异步调用中的Session问题
    在MVC的ApiController中实现统一校验
    使用 AndroidX86 在虚拟机中作为调试设备
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5668231.html
Copyright © 2011-2022 走看看