cf1072B. Curiosity Has No Limits(枚举)

Posted 自为

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf1072B. Curiosity Has No Limits(枚举)相关的知识,希望对你有一定的参考价值。

题意

题目链接

给出两个序列(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;
}
/*

*/

以上是关于cf1072B. Curiosity Has No Limits(枚举)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 刷题记录

CF 39E. What Has Dirichlet Got to Do with That?(记忆化搜索+博弈论)

HDU 1017 A Mathematical Curiosity (枚举水题)

HDU 1017 A Mathematical Curiosity (输出格式,穷举)

DXP中出现“has no driving Source”是怎么回事?

python通过grpc调用tfserving报错has no attribute 'beta_create_PredictionService_stub'