/**//* 给出A,B ,求X,Y,使得 A = X + Y, B = X xor Y。要使得X最小,若不存在输出-1 0<=A,B<2^64
看了解题报告的,挺巧的,切入点是:“使得X最小” -----------------OMG 若(X,Y)是满足条件的一对数,则检查每一位 若Xi = 1, Yi = 0 则可交换这两位,上面的等式还是成立,但是X减小了,Y增大了 完成上面的操作后,(X,Y)的情况只能是(0,1),(0,0),(1,1) 则有 Y - X = X xor Y = B -------------------OMG 所以 X = (A-B)/2 , Y = (A+B)/2
巧丫.. */ #include<iostream> #include<cstring> #include<map> #include<algorithm> #include<stack> #include<queue> #include<cmath> #include<string> #include<cstdlib> #include<vector> #include<cstdio> #include<set> #include<list> #include<numeric> #include<cassert> #include<ctime> #include<bitset>
using namespace std;
int main() { #ifndef ONLINE_JUDGE freopen("in","r",stdin); #endif
for (unsigned long long A, B; cin>>A>>B; ) { //A = X + Y, B = X ^ Y . X is minimal //swap(xi,yi) if xi = 1 and yi = 0, the equalities above mantian. //after all the swaping, we can find that //(xi,yi) can only be (0,1) , (0,0), (1,1) //so X ^ Y = Y - X = B if (((A&1) ^ (B&1)) || A < B) { cout << -1 << endl; } else { cout << (A-B)/2 <<" "<< (A+B)/2<<endl; } } return 0; }
|