hdu 5142(数学-进制转换)
2016-07-13 21:16
405 查看
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
[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each query,print the reversed number in a separate line.
[align=left]Sample Input[/align]
3
6
8
1
[align=left]Sample Output[/align]
3
1
1
[align=left]Source[/align]
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); } }
相关文章推荐
- RT-Thread创建静态、动态线程
- 链表的头结点和尾节点的用处
- SearchView简单示例
- Python+Selenium+PIL+Tesseract真正自动识别验证码进行一键登录
- 最优配对问题
- 欢迎使用CSDN-markdown编辑器
- Day three
- git日志输出格式及两个版本之间差异列表
- Redis详解:lists数据类型及操作
- 【leetcode】165. Compare Version Numbers
- 第十七天、迷宫游戏
- 在多级存储体系中,“Cache-主存”结构的作用是解决( )的题目。----腾讯2014研发笔试卷
- linux下查看系统进程占用的句柄数
- 第143课: Spark面试经典系列之Reduce端OOM和shuffle file not found如何解决?
- html area图片热点的使用介绍附相关属性一览表
- 深入理解Java的接口和抽象类
- 按键槽的写法
- 利用Gradle发布项目到JCenter、Maven
- Qt之保持GUI响应
- Hdu 5352 MZL's City (最小费用最大流)