2021牛客多校第七场

August 24, 2021 · 算法 · 2354次阅读

I xay loves or

题意

给定x和s,问有多少个正整数y满足x|y=s

题目理解

这tm还能有啥理解,当时交了n发就是过不去。最后发现自己是真nt,无视正整数三个字,果然是小垃圾。

代码

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>

#define fo(ii, nn) for(int ii=1;ii<=nn;ii++)

using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pai;
const int N = 5000000 + 10;
const int mod = 1e9 + 7;
int n, c;
double w[N];

inline bool read(ll &num) {
    //quick read
    char in;
    bool IsN = false;
    in = getchar();
    if (in == EOF) return false;
    while (in != '-' && (in < '0' || in > '9')) in = getchar();
    if (in == '-') {
        IsN = true;
        num = 0;
    } else num = in - '0';
    while (in = getchar(), in >= '0' && in <= '9') { num *= 10, num += in - '0'; }
    if (IsN) num = -num;
    return true;
}

ll qp(int b, int p) {
    ll ans = 1;
    ll base = b, ansp = p;
    for (; p; p >>= 1) {
        if (p & 1) ans = (long long) ((ans * base));
        base = (long long) ((base * base));
    }
    return ans;
}

void solve() {
    ll x, s;
    ll ans = 1;
    bool f = false;
    cin >> x >> s;
    ll xx=x,ss=s;
    while (x && s) {
        ll curx = x % 2, curs = s % 2;
        x /= 2;
        s /= 2;
        //cout<<curx;
        if (curx && curs) {
            ans *= 2;
        } else if (curx && !curs) {
            ans = 0;
            f = true;
            break;
        }
    }
    if (f) {
        cout << ans;
        return;
    }
    if (x && !s)
        ans = 0; // x位数比s还多那肯定或不出来

    if ((0 | xx) == ss) {
        if (ans - 1 > 0) ans -= 1;
        else ans = 0;
    }
    cout << ans;
}

int main() {
    int t;
    solve();
    return 0;
}

牛客多校

最后编辑于3年前

添加新评论