• Codeforces 1325D Ehab the Xorcist(构造+异或)


    题意:给出u,v,分别表示数组a的异或和,和数组a的和。求构造出最短的数组a。u<1e18

    题解:显然u>v || (u&1)!=(v&1)无解,u==v=0时,数组为空,u==v!=0时,数组长度为1,元素为u即可。开始考虑构造,0^u=u,可令x=(v-x)/2,则x x u 满足条件,当(x^u)==(v-x)时,可化简成x^u, x。

    #include <bits/stdc++.h>
    #define IOS ios::sync_with_stdio(false);cin.tie(0)
    #define fre freopen("C:\in.txt", "r", stdin)
    #define _for(i,a,b) for(int i=a; i< b; i++)
    #define _rep(i,a,b) for(int i=a; i<=b; i++)
    #define lowbit(a) ((a)&-(a))
    #define inf 0x3f3f3f3f
    #define endl "
    "
    using namespace std;
    typedef long long ll;
    template <class T>
    void read(T &x)
    {
        char c; bool op=0;
        while(c=getchar(), c<'0'||c>'9') if(c=='-') op=1;
        x=c-'0';
        while(c=getchar(), c>='0'&&c<='9') x=x*10+c-'0';
        if(op) x=-x;
    }
    
    ll T, u, v;
    
    int main()
    {
        //fre;
        T=1;
        //read(T);
        while(T--)
        {
            read(u), read(v);
            ll x=(v-u)/2;
            if(u>v || (u&1)!=(v&1)) printf("-1
    ");
            else if(u==v && u==0) printf("0
    ");
            else if(u==v) printf("%d
    %lld", 1, u);
            else if((x^u)==(v-x)) printf("%d
    %lld %lld
    ", 2, x^u, x);
            else printf("%d
    %lld %lld %lld
    ", 3, x, x, u);
        }
        return 0;
    }
  • 相关阅读:
    挂载nfs网络共享目录到本地目录报错
    ubuntu18.04,centos7.7下安装nfs详细步骤
    linux的fstab配置文件
    nginx整合php后,浏览器访问.php文件报错
    centos中安装php7.3.13(目前最新版)
    skills_nginx
    problems_ubuntu
    problems_nginx
    docker中部署halo
    数论学习
  • 原文地址:https://www.cnblogs.com/Yokel062/p/13458068.html
Copyright © 2020-2023  润新知