【CUGBACM15级BC第22场 A】hdu 5142 NPY and FFT
来源:互联网 发布:金英杰免费网络课登录 编辑:程序博客网 时间:2024/05/30 05:29
NPY and FFT
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1064 Accepted Submission(s): 699
Total Submission(s): 1064 Accepted Submission(s): 699
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 integerX(0≤X≤231−1 ),the given number.
The next T lines,each contains a integer
Output
For each query,print the reversed number in a separate line.
Sample Input
3681
Sample Output
311
题意:把n转换为二进制再翻转,去掉前导零后的数是多少
思路:用数组保存二进制,处理前导零即可
#include <iostream>#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <algorithm>#include <functional>#include <ctime>#define PI acos(-1)#define eps 1e-8#define inf 0x3f3f3f3f#define debug(x) cout<<"---"<<x<<"---"<<endltypedef long long ll;using namespace std;long long quickpow(long long a, long long b){ if (b < 0) { return 0; } long long ret = 1; for (; b; b >>= 1, a = (a * a)) if (b & 1) { ret = (ret * a); } return ret;}int a[55];int main(){ std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { memset(a, 0, sizeof(a)); int x; cin >> x; int cnt = 0, flag; while (x) { a[++cnt] = x % 2; x /= 2; } for (int i = 1; i <= cnt; i++) { if (a[i] == 1) { flag = i; break; } } ll ans = 0; for (int i = flag; i <= cnt; i++) { ans += quickpow(2, cnt - i) * a[i]; } cout << ans << endl; } return 0;}
阅读全文
0 0
- 【CUGBACM15级BC第22场 A】hdu 5142 NPY and FFT
- 【CUGBACM15级BC第22场 C】hdu 5144 NPY and shot
- 【CUGBACM15级BC第22场 B】hdu 5143 NPY and arithmetic progression
- 【CUGBACM15级BC第15场 A】hdu 5083 Love
- 【CUGBACM15级BC第17场 A】hdu 5100 Chessboard
- 【CUGBACM15级BC第23场 A】hdu 5146 Sequence
- 【CUGBACM15级BC第8场 A】hdu 4989 Summary
- 【CUGBACM15级BC第31场 A】hdu 5178 pairs
- 【CUGBACM15级BC第1场 A】hdu 4857 逃生
- 【CUGBACM15级BC第11场 A】hdu 5054 Alice and Bob
- 【CUGBACM15级BC第19场 A】hdu 5108 Alexandra and Prime Numbers
- 【CUGBACM15级BC第25场 A】hdu 5154 Harry and Magical Computer
- 【CUGBACM15级BC第27场 A】hdu 5162 Jump and Jump...
- 【CUGBACM15级BC第7场 A】hdu 4985 Little Pony and Permutation
- 【CUGBACM15级BC第14场 A】Harry And Physical Teacher
- 【CUGBACM15级BC第11场 B】hdu 5055 Bob and math problem
- 【CUGBACM15级BC第25场 B】hdu 5155 Harry And Magic Box
- 【CUGBACM15级BC第7场 B】hdu 4986 Little Pony and Alohomora Part I
- 《时间有泪》
- Python爬虫——自制简单的搜索引擎
- jquery $.trim()方法
- 单链表实现一元多项式乘法
- 【UWP开发】unity发布win10报错Exception: Failed to restore NuGet packages
- 【CUGBACM15级BC第22场 A】hdu 5142 NPY and FFT
- FZU 2282 Wand(错排+费马小定理)
- 正则表达式
- java_api操作zookeeper节点
- javascript知识点函数及对象的基本介绍
- 考研路茫茫——单词情结 HDU
- USACO-2017-JAN-金组 Cow Navigation
- 2017"百度之星"程序设计大赛
- ShaderLab: Culling & Depth Testing