hdu-
来源:互联网 发布:sql 保留小数位数 编辑:程序博客网 时间:2024/04/28 07:56
Bitwise Equations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 645 Accepted Submission(s): 343
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解体思路:这道题目可以这样想,就是求出x的二进制,k的二进制,x的二进制序列中只有等于零处可以填充k的二进制数,要将k的二进制数填完。填好后,再转换成十进制后就是答案。代码如下:#include<stdio.h>#include<cmath>int a[40];int b[40];int main(){int t;int x,k,num,d,l;long long m;scanf("%d",&t);while(t--){d=0;l=0;num=0;m=0;scanf("%d%d",&x,&k); while(x){ if(x%2==0){ a[++d]=l;//d表示一共有多少的零 } x=x/2; l++;//从0位开始计算 } while(k){ b[++num]=k%2; k=k/2; } for(int i=1;i<=d&&i<=num;i++) m+=b[i]*pow(2,a[i]); if(num>d){ for(int i=d+1;i<=num;i++){ m+=b[i]*pow(2,l); l++; } } printf("%lld\n",m);}return 0;}
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 聚类和判别分析小论文
- Codeforces Round #336 (Div. 2) 608C Chain Reaction(dp)
- 【hadoop】ssh localhost 免密码登陆(图解)
- Javascript DOM 编程艺术(second edition) 读书笔记(3)
- 我的第一个docker镜像
- hdu-
- Android选择头像(从相机-相册-截图获取),以及闪退的解决
- hihocoder 1107 : Shortest Proper Prefix
- OpenCV 学习笔记
- 欢迎阅读我的博客
- Thread (线程)(杂记)
- swift 基础1
- node.js之打包工具webpack
- My97DatePicker时间控件