http://codeforces.com/contest/1072/problem/B

开始想的只有搜索,时间复杂度$O(4^n)$,明显有问题。

想了半个小时没有思路,然后想到了正难则反,就开始步入正轨。

题目给出了$a[ ]$和$b[ ]$数组,首先与处理,我们枚举每一种情况的$a[i]$和$b[i]$,然后枚举ans[i]表示当为$ans[i]$时下一个数可以填几,预处理完你会发现,有合法的数对的情况只有一种。

预处理时间复杂度$O(4^4)$

接下来我们可以枚举答案序列的第一位填啥,从而可以推出其他的数字填啥。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int f[][][];
int n,a[],b[],ans[];
bool check()
{
for(int i=;i<=n;i++)
{
ans[i]=f[a[i]][b[i]][ans[i-]];
if(ans[i]==-)return ;
}
return ;
}
int main()
{
memset(f,-,sizeof(f));
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
for(int k=;k<=;k++)
{
for(int p=;p<=;p++)
{
int x=p|k,y=p&k;
if(x==i&&y==j)f[i][j][k]=p;
}
}
}
}
bool flag=;
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=;i<=n;i++)scanf("%d",&b[i]);
for(int i=;i<=;i++)
{
ans[]=i;
if(check())
{
flag=;
break;
}
}
if(!flag)printf("NO");
else
{
printf("YES\n");
for(int i=;i<=n;i++)printf("%d ",ans[i]);
}
}

Codeforces 517 #B的更多相关文章

  1. Codeforces 517 #A

    http://codeforces.com/contest/1072/problem/A 题目挺简单,就是让你求几个环,占得方格的个数,然而题目为什么给出了公式呢? 然而给出的公式辣么丑,还是不用的好 ...

  2. 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++ ...

  3. Codeforces Round #517 体验记

    原文链接 https://www.cnblogs.com/zhouzhendong/p/CF1071.html 赛前: 呀,这个 Round # 必须打啊. 于是临时改变注意决定打这一场.用小号打. ...

  4. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  5. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  6. Codeforces Round #517 (Div. 2) C. Cram Time(思维+贪心)

    https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数 ...

  7. Codeforces Round #517 (Div. 2)(1~n的分配)

    题:https://codeforces.com/contest/1072/problem/C 思路:首先找到最大的x,使得x*(x+1)/2 <= a+b 那么一定存在一种分割使得 a1 &l ...

  8. Codeforces Round #517 Div. 2/Div. 1

    \(n\)天没更博了,因为被膜你赛的毒瘤题虐哭了... 既然打了这次CF还是纪念一下. 看看NOIP之前,接下来几场的时间都不好.这应该是最后一场CF了,差\(4\)分上紫也是一个遗憾吧. A 给一个 ...

  9. Codeforces Round #517 (Div. 2)

    A #include<queue> #include<cstdio> #include<cstring> #include<algorithm> #de ...

随机推荐

  1. HTTPRunner实践二——数据驱动

    基于文档http://cn.httprunner.org/advanced/data-driven/ 场景一:用例集+独立参数+参数列表 1.原始用例文件savePatient_01.yml - co ...

  2. Mac终端操作移动硬盘文件命令

    桌面上看到的硬盘都挂载在 /Volumes目录下 例如移动硬盘名为ZTB,有System目录,则应输入命令: cd /Volumes/ZTB/System 注意:进入Volumes目录命令为cd /V ...

  3. CodeForces - 851B -Arpa and an exam about geometry(计算几何)

    Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points a,  ...

  4. hdu2027 trie树 字典树模板

    #include <iostream> #include <cstdio> #include <cstring> #include <sstream> ...

  5. ]NET Core Lucene.net和PanGu分词实现全文检索

    Lucene.net和PanGu分词实现全文检索 Lucene.net(4.8.0) 学习问题记录五: JIEba分词和Lucene的结合,以及对分词器的思考   前言:目前自己在做使用Lucene. ...

  6. STM32之ADC(内部基准电压,参考电压)

    转 STM32内部参照电压VREFIN的使用 https://blog.csdn.net/uncle_guo/article/details/50625660 每个STM32芯片都有一个内部的参照电压 ...

  7. Ubuntu下安装nginx及使用

    首先介绍以下nginx.下图来自百科介绍:详细介绍地址:https://baike.baidu.com/item/nginx/3817705?fr=aladdin 在我们平时的开发娱乐中,也许并不会涉 ...

  8. SyntaxError: Use of const in strict mode.

    具体报错console c:\Users\Administrator\WebstormProjects\blogtest\node_modules\connect-mongo\src\index.js ...

  9. bootstrap fileinput 上传文件

    最近用到文件上传功能, 说实话:以前遇到过一次,COPY了别人的代码 结束! 这次又要用,可是看到别人很酷的文件上传功能,心痒了! 好吧.简单的办法,找控件: bootstrap fileinput ...

  10. 织梦修改文档HTML默认保存路径

    \data\config.cache.inc.php $cfg_arcdir = '/a'; 改为 $cfg_arcdir = '/';