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 (1≤T≤100).
The next T lines,each contains a integer X(0≤X≤231−1),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

BestCoder Round #22

题意:把一个数字换成二进制,然后将其二进制倒过来得到的新的数的十进制是多少?

题解:直接模拟这个过程.

#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\n",ans);
    }
}
时间: 2024-08-04 22:18:04

hdu 5142(数学-进制转换)的相关文章

hdu 2031(进制转换升级版)

1.这里有零的时候 2.考虑负数 3.就是考虑大于10的情况 #include <iostream> #include <cstdio> using namespace std; int a[100005]; int n,m; int main() { while(~scanf("%d %d",&n,&m)) { if(n==0) cout<<0; else if(n>0) { int i=0; while(n>0) {

HDU 4937 Lucky Number (数学,进制转换)

题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last); //把[first0,last0)之间的部分替换成[first,last)之间的字符串 /* 题意: 我们将3,4,5,6认为是幸运数字.给定一个十进制数n. 现在可以讲起任意转

hdu 4937 Lucky Number ( 进制转换+枚举 )

题意: 有一个数n,问有多少个进制x(基数)使得n转换为x进制后的数字中只有3.4.5.6四个数. 算法: 对于只有一位数的情况,显然3.4.5.6都应该输出-1. 如果有2位数,假设这2位中高位为a,低位为b,进制为base,则 n = a * base + b,解一元一次方程即可. 如果有3位数,假设这3为从高到低分别为a.b.c,进制为base,则 n = a * base * base + b * base + c,即一元二次方程即可. 如果位数>= 4,可以暴力枚举进制数.base>

枚举 + 进制转换 --- hdu 4937 Lucky Number

Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 294    Accepted Submission(s): 49 Problem Description “Ladies and Gentlemen, It’s show time! ” “A thief is a creative artist who ta

hdu 2031 进制转换

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2031 题目大意:进制转换,先变成十进制在进行进制间的转化. 1 #include<stdio.h> 2 int main() 3 { 4 int n,m,i,j,f,p; 5 char a[200]; 6 while(scanf("%d%d",&n,&m)!=EOF) 7 { 8 i=0; 9 p=0; 10 if(n<0) 11 { 12 p=-1; 1

数学运算高级工具bc:小数精度;进制转换;计算平方及平方根

bc是一个用于数学运算的高级工具,包含了大量选项,可以借助它执行浮点数运算并应用一些高级函数: [[email protected] ~]# echo 3*2.12 | bc 6.36 [[email protected] ~]# n=54 [[email protected] ~]# m=`echo "$n*1.5" | bc` [[email protected] ~]# echo $m 81.0 [[email protected] ~]# 其他二代参数可以放在要执行的具体操作前

HDU 5186 zhx&#39;s submissions (进制转换)

Problem Description As one of the most powerful brushes, zhx submits a lot of code on many oj and most of them got AC. One day, zhx wants to count how many submissions he made on n ojs. He knows that on the ith oj, he made ai submissions. And what yo

hdu 4937 Lucky Number(数学题 进制转换)2014多校训练第7场

Lucky Number                                                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description "Ladies and Gentlemen, It's show time! " "A thie

CodeForces 1B-字符串,进制转换与数学

一个萌新的成长之路 Background 同学们都回家了,只有我和wjh还有邢神在机房敲代码,吃random口味的方便面-- Description Translated by @PC_DOS from luogu In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the se