题意

题目链接

给出两个序列\(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. bzoj 3895: 取石子

    $ \color{#0066ff}{ 题目描述 }$ Alice和Bob两个好朋含友又开始玩取石子了.游戏开始时,有N堆石子 排成一排,然后他们轮流操作(Alice先手),每次操作时从下面的规则中任选 ...

  2. 重写成员“MySql.Data.Entity.MySqlConnectionFactory.CreateConnection(System.String)”时违反了继承安全性规则。重写方法的安全可访问性必须与所重写方法的安全可访问性匹配。

      1,程序中使用加载反射出现下面的问题: 无法加载一个或多个请求的类型.有关更多信息,请检索 LoaderExceptions 属性. 然后把代码改了一下, try { types.AddRange ...

  3. LeetCode153.寻找旋转排序数组中的最小值

    153.寻找旋转排序数组中的最小值 描述 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 请找出 ...

  4. LOJ6519. 魔力环(莫比乌斯反演+生成函数)

    题目链接 https://loj.ac/problem/6519 题解 这里给出的解法基于莫比乌斯反演.可以用群论计数的相关方法代替莫比乌斯反演,但两种方法的核心部分是一样的. 环计数的常见套路就是将 ...

  5. URAL - 1146

    从来不会DP的家伙终于要开始重拾DP了 最大子矩阵没啥好说的,注意单调最大子矩阵不用这么高复杂度,另行更新 #include<bits/stdc++.h> #define rep(i,j, ...

  6. [微信小程序] -- wxss引用外部css文件及iconfont

    小程序引入外部文件的方式是: 只需要在其css文件写上: @import "外部css地址.wxss"; 因为项目需要, 小程序中需要使用iconfont , 很容易就想到了H5的 ...

  7. Win10如何新建用户怎么添加新账户

    https://jingyan.baidu.com/article/25648fc162d5899190fd0069.html 很多朋友都是安装完Windows10系统后,直接使用超级管理员账号登录系 ...

  8. 剑指offer——面试题7:重建二叉树

    // 面试题7:重建二叉树 // 题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输 // 入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1, // 2, ...

  9. PIE SDK地图显示范围截图

    1.1. 功能简介 地图显示范围截图是将当前地图显示的范围进行输出.输出的 格式是png.bmp,主要思路就是通过IActiveView接口下的Output()方法进行输出 1.2. 功能实现说明 2 ...

  10. 后台返回的值ajax接收不到

    原因有很多种可能,我遇到的是后台写的Controller忘记了加@ResponseBody,导致springMVC把返回的字符串当成view了