计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
2015-12-27 12:11
369 查看
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.
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.
Output
For each case, output one line containing the number Y.
Sample Input
3 5 1 5 5 2000000000 2000000000
Sample Output
2 18 16383165351936
总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/fastcry.gif)
#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; } }
@执念 "@☆但求“❤”安★
下次我们做的一定会更好。。。。
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/tongue.gif)
为什么这次的题目是英文的。。。。QAQ...
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
相关文章推荐
- URLConnection的post请求网络数据和AsyncTask异步线程
- 计算机学院大学生程序设计竞赛(2015’12)Happy Value
- 计算机学院大学生程序设计竞赛(2015’12)The collector’s puzzle
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
- windows平台下 c/c++进行http通信的教训
- windows平台下 c/c++进行http通信的教训
- Ubuntu 网络管理器显示“设备未托管”的解决办法
- 计算机学院大学生程序设计竞赛(2015’12)The Country List
- 数据结构实验之排序七:选课名单
- special filter for iptables/netfilter tcpdump/tshark/wireshark
- C#检测网络连接
- DHCP源码分析-系统概述
- 黑马程序员——网络编程
- 杭州电子科技大学计算机学院大学生程序设计竞赛(2015'12)
- XMLHttpRequest对象
- 安卓日记——http中的get和post方法
- 数据结构实验之查找五:平方之哈希表
- SDUT 数据结构实验之排序二:交换排序
- 一个用js写的接口http调试程序
- 数据结构实验之查找七:线性之哈希表 151 268