zoukankan      html  css  js  c++  java
  • CF 517 div2 B

    传送门:http://codeforces.com/contest/1072/problem/B

    题意:给两组序列a,b,求一组序列 t 使得 t [ i ] | t [ i+1 ] == a [ i ],t [ i ] & t [ i+1 ] == b [ i ]

    0<= a [ i ],t [ i ] , b [ i ] < = 3

    先打个表找规律, 发现 x | y + x & y == x+ y

    位操作, 可以按位证一下

      x     y     x | y    x & y

      0    0       0         0

      0    1       1         0

      1    0       1         0

      1    1       1         1

    每位就4种情况,定下第一位,暴力判断就好啦

    #include<algorithm>
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<map>
    #include<queue>
    #include<stack>
    #include<list>
    #include<set>
    using namespace std;
    typedef long long ll;
    typedef pair<ll,ll> P;
    typedef long double ld;
    #define mem(x) memset(x, 0, sizeof(x))
    #define me(x) memset(x, -1, sizeof(x))
    #define fo(i,n) for(i=0; i<n; i++)
    #define sc(x) scanf("%I64d", &x)
    #define sca(n,m) scanf("%I64d%I64d", &n, &m)
    #define pr(x) printf("%I64d
    ", x)
    #define pri(x) printf("%I64d ", x)
    #define lowbit(x) x&-x
    const ll MOD = 1e9 + 7;
    const ll oo = 1e18;
    const ll N = 4e5 + 5;
    ll a[N], b[N], ans[N];
    int main()
    {
        ll i, j, k, l=1;
        ll n, m;
        /*for(i=0; i<=3; i++)
        {
            for(j=0; j<=3; j++)
            {
                n=i|j;
                m=i&j;
                cout<<i<<" "<<j<<" "<<n<<" "<<m<<endl;
            }
            cout<<endl;
        }*/
        cin>>n;
        for(i=1; i<n; i++) cin>>a[i];
        for(i=1; i<n; i++) cin>>b[i];
        for(i=0; i<=3; i++)
        {
            ans[1]=i;
            for(j=2; j<=n; j++)
            {
                ans[j]=a[j-1]+b[j-1]-ans[j-1];
                if((ans[j-1]|ans[j])!=a[j-1])break;
                if((ans[j-1]&ans[j])!=b[j-1])break;
            }
            if(j>n)
            {
                cout<<"YES"<<endl;
                for(j=1; j<=n; j++)
                    cout<<ans[j]<<" ";cout<<endl;
                return 0;
            }
        }
        cout<<"NO"<<endl;
        return 0;
    }
  • 相关阅读:
    【idea-部署web项目】
    【IDEA下使用tomcat部署web项目】
    【 PLSQL Developer安装、tnsnames.ora配置 解答】
    【idea--git】
    【Sping管理bean的原理】
    【关于eclipse的一些自己常用的插件】
    【Spring-任务调度】
    【mysql存储引擎】
    【mysql-索引+存储过程+函数+触发器-更新。。。】
    【转-mysql-explain介绍】
  • 原文地址:https://www.cnblogs.com/op-z/p/11313814.html
Copyright © 2011-2022 走看看