Codeforces Round #664 (Div. 2) C. Boboniu and Bit Operations
传送门:cf1395C
题意
c[i]=a[i]&b[j],b[j]是b数组中任意一个,求c[1] | c[2] | ... | c[n]最小值。
题解
经典的二进制枚举答案,因为a和b的最大值<29 ,所以最后的结果最大是9个位置全1,不会超过210 ,故只要枚举0到210-1即可。每次答案和a[i]&b[j]的值相与,如果有一个 j 可以使相与后答案不变,那么当前a[i]可以,如果没有,那么当前答案不可以。当所有a[i]都可行,输出答案,否则继续枚举。
代码
1 #include<bits/stdc++.h>
2 using namespace std;
3
4 int a[100100];
5 int b[100100];
6
7 int main()
8 {
9 ios::sync_with_stdio(false);
10 cin.tie(0);
11 cout.tie(0);
12 int n,m;
13 cin>>n>>m;
14 for(int i=0;i<n;i++) cin>>a[i];
15 for(int i=0;i<m;i++) cin>>b[i];
16 for(int i=0;i<(1<<10);i++){
17 int flag1=1;
18 for(int j=0;j<n;j++){
19 int flag2=0;
20 for(int k=0;k<m;k++){
21 if((i|(a[j]&b[k]))==i){flag2=1; break;}
22 }
23 if(!flag2) {flag1=0;break;}
24 }
25 if(flag1) {cout<<i<<endl;return 0;}
26 }
27 return 0;
28 }
Codeforces Round #664 (Div. 2) C. Boboniu and Bit Operations的更多相关文章
- Codeforces Round #664 (Div. 2) D. Boboniu Chats with Du
传送门:cf1395D 题意 给定一个长度为n的数组a[i]为当天说话的有趣值,如果a[i]>m,那么在 i 之后有d天不能说话.否则可以每天都说话.找到一个排列使得n天有趣值总和最大,问有趣值 ...
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations (矩阵高速幂)
题目地址:http://codeforces.com/contest/551/problem/D 分析下公式能够知道,相当于每一位上放0或者1使得最后成为0或者1.假设最后是0的话,那么全部相邻位一定 ...
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations 矩阵快速幂优化dp
D. GukiZ and Binary Operations time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations
得到k二进制后,对每一位可取得的方法进行相乘即可,k的二进制形式每一位又分为2种0,1,0时,a数组必定要为一长为n的01串,且串中不出现连续的11,1时与前述情况是相反的. 且0时其方法总数为f(n ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- WixVersionControl Wix项目版本控制
原文链接:https://www.swack.cn/wiki/001565675133949eff0d3d5a51f48288cf6d8248905e28f000/001569821278313e6b ...
- 【Azure Redis 缓存】Azure Redis功能性讨论
关于使用Azure Redis服务在以下九大方面的功能性的解说: 高可用 备份可靠性 配置自动化 部署多样性 快速回档功能 数据扩容 SLA稳定性 数据安全性 监控系统 一:高可用 Azure Cac ...
- 设置.ignore后不生效解决方案
/logs/*.lock /logs/*.log/reports/API_TEST_V*/.idea/ 设置.ignore后不生效解决方案: 在terminal中输入已下几行代码: git rm -r ...
- 【Linux】在文件的指定位置插入数据
今天遇到一个似乎很棘手的问题,要在文件的中间,插入几条配置 这里就以my.cnf这个文件为例 1 [mysqld] 2 datadir=/var/lib/mysql 3 socket=/var/lib ...
- 【Linux】rsync错误解析
rsync: Failed to exec ssh: No such file or directory (2) rsync error: error in IPC code (code 14) at ...
- 如何构建一个多人(.io) Web 游戏,第 2 部分
原文:How to Build a Multiplayer (.io) Web Game, Part 2 探索 .io 游戏背后的后端服务器. 上篇:如何构建一个多人(.io) Web 游戏,第 1 ...
- 剑指 Offer 27. 二叉树的镜像
同LeetCode226翻转二叉树 1 class Solution { 2 public: 3 TreeNode* mirrorTree(TreeNode* root) { 4 if(root == ...
- centos7安装宝塔面板
在终端下执行如下命令 yum install -y wget && wget -O install.sh http://download.bt.cn/install/install.s ...
- 使用.net中的API网关模式封装微服务
在本文中,我们将了解如何使用API网关模式来封装微服务并抽象出底层实现细节,从而允许使用者拥有进入我们系统的一致入口点. 为了构建和测试我们的应用程序,我们需要: 1.Visual Studio 20 ...
- 如何用Python中自带的Pandas和NumPy库进行数据清洗
一.概况 1.数据清洗到底是在清洗些什么? 通常来说,你所获取到的原始数据不能直接用来分析,因为它们会有各种各样的问题,如包含无效信息,列名不规范.格式不一致,存在重复值,缺失值,异常值等..... ...