计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
来源:互联网 发布:数据漫游是什么意思 编辑:程序博客网 时间:2024/05/25 20:00
Bitwise Equations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 633 Accepted Submission(s): 335
Problem Description
You are given two positive integers X and K. Return the K-th smallest positive integer Y, for which the following equation holds: X + Y =X | Y
Where '|' denotes the bitwise OR operator.
Where '|' denotes the bitwise OR operator.
Input
The first line of the input contains an integer T (T <= 100) which means the number of test cases.
For each case, there are two integers X and K (1 <= X, K <= 2000000000) in one line.
For each case, there are two integers X and K (1 <= X, K <= 2000000000) in one line.
Output
For each case, output one line containing the number Y.
Sample Input
35 15 52000000000 2000000000
Sample Output
21816383165351936
#include <string.h>#include <iostream>using namespace std;long long rets=0;class jisuan{public: long long kthPlusOrSolution(int, int); string getBin(int);};string jisuan::getBin(int x){ string ret=""; if(x==0) { ret="0"; return ret; } while(x>0) { ret=char(x%2+'0')+ret; x/=2; } return ret;}long long jisuan::kthPlusOrSolution(int x, int k){ string strx, strk; strx=getBin(x); strk=getBin(k); int lx=strx.length()-1; int lk=strk.length()-1; string ret=""; while(lx>=0 && lk>=0) { if(strx[lx]=='1') { ret="0"+ret; --lx; } else { ret=strk[lk]+ret; --lx; --lk; } } while(lk>=0) ret=strk[lk--]+ret; for(int i=0;i<(int)ret.length();i++) rets=(rets<<1)+ret[i]-'0'; return rets;}int main(){ int n,x,k; jisuan bit; cin>>n; while(n--) { rets=0; cin>>x>>k; bit.kthPlusOrSolution(x,k); cout<<rets<<endl; }}
1 0
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
- HDU计算机学院大学生程序设计竞赛(2015’12)1005 Bitwise Equations
- 杭州电子科技大学计算机学院大学生程序设计竞赛(2015'12)Bitwise Equations (二进制)
- 计算机学院大学生程序设计竞赛(2015’12)(STL )
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
- 计算机学院大学生程序设计竞赛(2015’12)Happy Value
- 计算机学院大学生程序设计竞赛(2015’12)01 Matrix
- 计算机学院大学生程序设计竞赛(2015’12)Pick Game
- 计算机学院大学生程序设计竞赛(2015’12)Study Words
- hdu 计算机学院大学生程序设计竞赛(2015’11)质方数
- hdu 计算机学院大学生程序设计竞赛(2015’11)游乐场
- 计算机学院大学生程序设计竞赛(2015’11)
- hdu--计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- URLConnection的post请求网络数据和AsyncTask异步线程
- kafka 安装和测试
- 排序算法—堆排序算法分析与实现(Python)
- 计算机学院大学生程序设计竞赛(2015’12)Happy Value
- C函数指针
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
- C/C++中整数与浮点数在内存中的表示方式
- BZOJ3295 CQOI2011 动态逆序对
- Android应用开发之自定义View触摸相关工具类全解
- 安卓eclipse 的ndk开发
- 计算机学院大学生程序设计竞赛(2015’12)01 Matrix
- Qt之文件操作
- 随机数产生器(random number generator)
- spring源码编译为eclipse项目