比赛的时候题目意思完全不对.....居然还有人1分钟就AC了......
NPY and FFT
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 132 Accepted Submission(s): 86
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?
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.
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
/* ***********************************************
Author :CKboss
Created Time :2014年12月13日 星期六 19时00分45秒
File Name :A.cpp
************************************************ */
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;
int arr[50],an=0;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T_T,n;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d",&n);
bool ok=false;
int m=0,an=0;
for(int i=31;i>=0;i--)
{
if(n&(1<<i)) ok=true;
if(ok==true)
{
arr[an++]=((n&(1<<i))==0)?0:1;
}
}
reverse(arr,arr+an);
for(int i=0;i<an;i++)
{
if(arr[i]) m|=(1<<(an-i-1));
}
printf("%d\n",m);
}
return 0;
}