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;
}
/*
*/
作者:自为风月马前卒
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。