2015’12杭电校赛1005 Bitwise Equations(二进制找规律)
来源:互联网 发布:window安装mac双系统 编辑:程序博客网 时间:2024/05/22 06:47
题解
有T(100)组数据, 对于每组数据,给定X,K(1<=X,K<=2e9)
让你求出,满足X+Y==X|Y的第K小的Y
很显然, X+Y==X|Y的Y,需要满足的性质是——
X二进制是1的位置,Y必须是0;X二进制是0的位置,Y必须是1。
代码
#include<cstdio>#include <cstring>#include <iostream>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <string>#include <set>#include <ctime>#include <cmath>#include <cctype>#define ll long longusing namespace std;int t;ll x, k, y;ll a[100], b[100];int main(){ scanf("%d", &t); while (t--) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); scanf("%lld%lld", &x, &k); ll i, al, bl; for (i = 0; x; i++) { a[i] = x & 1; x >>= 1; } al = i; for (i = 0; k; i++) { b[i] = k & 1; k >>= 1; } bl = i; y = 0; ll j = 0; for (i = 0; j < bl; i++) { if (a[i] == 1) a[i] = 0; else a[i] = b[j++]; y += a[i] << i; } printf("%lld\n", y); } return 0;}
题目
Bitwise Equations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 713 Accepted Submission(s): 376
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
0 0
- 2015’12杭电校赛1005 Bitwise Equations(二进制找规律)
- 杭州电子科技大学计算机学院大学生程序设计竞赛(2015'12)Bitwise Equations (二进制)
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
- HDU计算机学院大学生程序设计竞赛(2015’12)1005 Bitwise Equations
- 【杭电2015年12月校赛E】【二进制拆分】Bitwise Equations 第K小的X满足X或Y=X+Y
- ZOJ 3870Team Formation(二进制找规律)
- SGU 126. Boxes 找规律 数学 二进制
- vijos - P1319数列 (二进制 + 找规律 + python)
- HDU 5573 Binary Tree 找规律二进制
- hdu 1005 找规律(循环点)
- HDU——1005(找规律)
- hdu 1005 Number Sequence(找规律)
- hdu 1005 找规律(好坑!!)
- HDU 1005-Number Sequence(找规律)
- hdoj 1005 number sequence(找规律)
- HDU 1005 找规律
- HDOJ1021(找规律)
- Service与Android系统实现(1)-- 应用程序里的Service
- 树莓派错误“No space left on device”
- Bootstrap导航元素
- unicode WCHAR 与多字符集char相互转换
- 【黑马程序员】第八章:IO(输入输出)
- 2015’12杭电校赛1005 Bitwise Equations(二进制找规律)
- 24. Swap Nodes in Pairs
- Scala 并发编程之react和loop
- JDK配置步骤
- MyBatis Generator产生的Example类
- js中eval函数对json格式数据的处理
- BATCHSQL--GoldenGate Parameter
- 多种设计模式核心思想对比
- javascript小白学习指南4--持续更新