zoukankan      html  css  js  c++  java
  • Codeforces635C XOR Equation【数学】

    题目链接:

    http://codeforces.com/contest/635/problem/C

    题意:

    给定两个数的和s及异或x,求两个数的可能情况。

    分析:

    我们有公式a+b=a& b2+a ^ b
    这样对于与和异或的结果一位一位的来考虑即可。
    注意:

    1. 题目特别强调Two positive integers a and b,所以在sx相等时,我们要减去0的情况。
    2. 差为奇数的情况很明显不存在ab。
    3. 按位判断的时候注意xx和tt都为1的情况也是不存在的。

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    using namespace std;
    #define pr(x) cout << #x << ": " << x << "  "
    #define pl(x) cout << #x << ": " << x << endl;
    #define sa(x) scanf("%d",&(x))
    #define sal(x) scanf("%I64d",&(x))
    #define mdzz cout<<"mdzz"<<endl;
    const int maxn = 2e5 + 5, oo =0x3f3f3f3f;
    typedef long long ll;
    //a + b = a & b * 2 + a ^ b
    int main (void)
    {
        ll s, x;sal(s);sal(x);
        ll t = s - x;
        if(t & 1) return puts("0"),0;
        t >>= 1;
        int tt = 1, xx = 1;
        ll ans = 1;
        ll tx = x;
        while(t || x){
            tt = t & 1;
            xx = x & 1;
            if(!tt && xx) ans <<= 1;
            if(tt && xx) return puts("0"), 0;
            t >>= 1;
            x >>= 1;
        }
        if(s == tx) ans -= 2;
        printf("%I64d", ans);
        return 0;
    }
    
  • 相关阅读:
    入门系列4
    入门系列3
    入门系列2
    入门系列1
    sql进阶-筛选库表中数据为空的表
    sql进阶-删除所有的视图
    sql序列(2) sql语句功能表
    sql序列(5)事务
    sql序列(4)存储过程
    KVM虚拟化介绍
  • 原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758631.html
Copyright © 2011-2022 走看看