题意

题目链接

给出两个序列\(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(枚举)的更多相关文章

  1. CF1072B Curiosity Has No Limits

    思路: 对于序列t,只要第一个数确定了,后续的数也随之确定了.枚举四种情况即可.实现: #include <iostream> #include <vector> using ...

  2. CodeForce 517 Div 2. B Curiosity Has No Limits

    http://codeforces.com/contest/1072/problem/B B. Curiosity Has No Limits time limit per test 1 second ...

  3. CF-1027-B. Curiosity Has No Limits

    CF-1027-B. Curiosity Has No Limits http://codeforces.com/contest/1072/problem/B 题意: 给定两组序列a,b,长度为n-1 ...

  4. Technocup 2019 - Elimination Round 2

    http://codeforces.com/contest/1031 (如果感觉一道题对于自己是有难度的,不要后退,懂0%的时候敲一遍,边敲边想,懂30%的时候敲一遍,边敲边想,懂60%的时候敲一遍, ...

  5. Codeforces 1072 - A/B/C/D - (Done)

    链接:http://codeforces.com/contest/1072/ A - Golden Plate - [计算题] #include<bits/stdc++.h> using ...

  6. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  7. HDU 1017 A Mathematical Curiosity(枚举)

    题目链接 Problem Description Given two integers n and m, count the number of pairs of integers (a,b) suc ...

  8. HDU 1017 A Mathematical Curiosity (枚举水题)

    Problem Description Given two integers n and m, count the number of pairs of integers (a,b) such tha ...

  9. 如何解决编译linux内核(解决声卡问题),遭遇fatal error: linux/limits.h: 没有那个文件或目录

    最近帮一位上海的朋友搞一块小板,在ubuntu15.04 vivid上已经加载了对应了.ko驱动包 但关键是系统根本就枚举不到该声卡ALC5640,试了OpenSUSE也是一样的结果,看来是内核漏加载 ...

随机推荐

  1. 安装python发行版本,并用conda来管理Environments,Python,packages

    简介:anaconda指的是一个开源的python发行版本,其包含了conda.Python等180多个科学包及其依赖项. 因为包含了大量的科学包,Anaconda 的下载文件比较大(约 515 MB ...

  2. yum国内镜像配置

    yum默认链接的还是国外的镜像,速度相对不理想,配置成国内的镜像会快很多,这里以阿里镜像为例进行配置: CentOS系统更换软件安装源 #base源#第一步:备份你的原镜像文件,以免出错后可以恢复.m ...

  3. 洛谷 P2515 [HAOI2010]软件安装(缩点+树形dp)

    题面 luogu 题解 缩点+树形dp 依赖关系可以看作有向边 因为有环,先缩点 缩点后,有可能图不联通. 我们可以新建一个结点连接每个联通块. 然后就是树形dp了 Code #include< ...

  4. 洛谷 P2680 运输计划(NOIP2015提高组)(BZOJ4326)

    题目背景 公元 \(2044\) 年,人类进入了宇宙纪元. 题目描述 公元\(2044\) 年,人类进入了宇宙纪元. L 国有 \(n\) 个星球,还有 \(n-1\) 条双向航道,每条航道建立在两个 ...

  5. I Hate It(线段树区间最值,单点更新)-------------蓝桥备战系列

    很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.  这让很多学生很反感.  不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老 ...

  6. bzoj1934 Vote 善意的投票 最小割(最大匹配)

    题目传送门 题目大意:很多小朋友,每个小朋友都有自己的立场,赞成或者反对,如果投了和自己立场不同的票会得到一个能量.又有很多朋友关系,如果一个人和他的一个朋友投的票不同,也会得到一个能量,现在问,通过 ...

  7. POJ - 1456 贪心 堆常用操作 注意细节

    题意:给定n个商品的deadline和profit,求每天卖一件的情况下的最大获利 显然是一道贪心 按deadline从小到大排序好,动态维护小根(profit)堆的大小<=当前deadline ...

  8. Wscript的popup

    Dim WSHShell Set WSHShell = WScript.CreateObject("WScript.Shell") WshSHell.popup "枚举主 ...

  9. java 并发完成任务之CountDownLatch

    1.CountDownLatch是一个同步辅助类,犹如倒计时计数器,创建对象时通过构造方法设置初始值,调用CountDownLatch对象的await()方法则处于等待状态,调用countDown() ...

  10. 详解Oracle hints PQ_DISTRIBUTE

    PQ_DISTRIBUTE是并行的hints中稍微复杂一点的一个 下面就这个hints做以下说明: 1.使用格式 /+ PQ_DISTRIBUTE(tablespec outer_distributi ...