欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

cf1072B. Curiosity Has No Limits(枚举)

程序员文章站 2022-03-10 15:10:25
题意 "题目链接" 给出两个序列$a, b$,求出一个序列$t$,满足 $$a_i = t_i | t_{i + 1}$$ $$b_i = t_i \& t_{i + 1}$$ 同时,$0 \leqslant a_i, b_i, t_i \leqslant 3$ Sol 打比赛的时候想到了拆位,从此 ......

题意

题目链接

给出两个序列\(a, b\),求出一个序列\(t\),满足

\[a_i = t_i | t_{i + 1}\]

\[b_i = t_i \& t_{i + 1}\]

同时,\(0 \leqslant a_i, b_i, t_i \leqslant 3\)

sol

打比赛的时候想到了拆位,从此走上不归路。。。

显然,当最后一位确定了之后,其他的数也都跟着确定了,。。

所以暴力枚举每个位置上是哪个数就行。。

/*
*/
#include<bits/stdc++.h> 
#define pair pair<int, int>
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
#define ll long long 
#define rg register 
#define pt(x) printf("%d ", x);
#define fin(x) {freopen(#x".in","r",stdin);}
#define fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int maxn = 1e6 + 10, inf = 1e9 + 10, mod = 1e9 + 7, b = 1;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n, a[maxn], b[maxn], f[maxn];
void solve(int val) {
    f[n] = val;
    for(int i = n - 1; i >= 1; i--) {
        bool flag = 0;
        for(int j = 0; j <= 3; j++) {
            int nx = f[i + 1]; f[i] = j;
            if((a[i] == (f[i] | f[i + 1])) && (b[i] == (f[i] & f[i + 1]))) {flag = 1; break;}
        }
        if(!flag) return ;
    }
    puts("yes");
    for(int i = 1; i <= n; i++) printf("%d ", f[i]);
    exit(0);
}
main() {
    //fin(a);
    n = read();
    for(int i = 1; i <= n - 1; i++) a[i] = read();
    for(int i = 1; i <= n - 1; i++) b[i] = read();

    solve(0); solve(1); solve(2); solve(3);
    puts("no");
    return 0;
}
/*

*/