Codeforces--631A--Interview(位运算)
Interview
Crawling in process...
Crawling failed
Time Limit:1000MS
Memory Limit:262144KB
64bit IO Format:%I64d & %I64u
Description
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function f(x, l, r) as a bitwise OR of integers
xl, xl + 1, ..., xr,
where xi is the
i-th element of the array
x. You are given two arrays a and
b of length n. You need to determine the maximum value of sum
f(a, l, r) + f(b, l, r) among all possible
1 ≤ l ≤ r ≤ n.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays.
The second line contains n integers
ai (0 ≤ ai ≤ 109).
The third line contains n integers
bi (0 ≤ bi ≤ 109).
Output
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible
1 ≤ l ≤ r ≤ n.
Sample Input
5
1 2 4 3 2
2 3 3 12 1
22
10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6
46
Sample Output
Hint
Bitwise OR of two non-negative integers a and
b is the number c = aORb, such that each of its digits in binary notation is
1 if and only if at least one of
a or b have
1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is l = 2 and
r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2
OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose
l = 1 and r = 4,
l = 1 and r = 5,
l = 2 and r = 4,
l = 2 and r = 5,
l = 3 and r = 4, or
l = 3 and r = 5.
In the second sample, the maximum value is obtained for
l = 1 and r = 9.
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
__int64 num1[1010],num2[1010];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
for(int i=1;i<=n;i++)
{
cin>>num1[i];
if(i>1) num1[1]|=num1[i];
} for(int i=1;i<=n;i++)
{
cin>>num2[i];
if(i>1) num2[1]|=num2[i];
}
cout<<num1[1]+num2[1]<<endl;
}
return 0;
}
Codeforces--631A--Interview(位运算)的更多相关文章
- CodeForces 282C(位运算)
C. XOR and OR time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- codeforces 631A Interview
A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces 631A Interview【模拟水题】
题意: 模拟模拟~~ 代码: #include<iostream> using namespace std; const int maxn = 1005; int a[maxn], b[m ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400
题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】
A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #443 (Div. 2) C 位运算
C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 620E New Year Tree(线段树+位运算)
题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...
随机推荐
- 40条常见的移动端Web页面问题解决方案
1.安卓浏览器看背景图片,有些设备会模糊.想让图片在手机里显示更为清晰,必须使用2x的背景图来代替img标签(一般情况都是用2倍).例如一个div的宽高是100100,背景图必须得200200,然后b ...
- x shell 连接不上本地虚拟机
登陆虚拟机服务器 输入ipconfig查看ip 地址(如果提示命令不存在,输入 ip addr) 输出结果中看标记处是否出现ip地址.我的打开后这里是没有地址的 然后输入 vi /etc/syscon ...
- 第一章 Linux命令行简介
1 Linux系统命令操作语法的格式 命令_[参数选项]_[文件或路径] 其中 _ 至少一个空格 如:rm -f /etc/hosts 其中/etc/hosts完整路径不带空格 ...
- Python爬虫入门教程: 27270图片爬取
今天继续爬取一个网站,http://www.27270.com/ent/meinvtupian/ 这个网站具备反爬,so我们下载的代码有些地方处理的也不是很到位,大家重点学习思路,有啥建议可以在评论的 ...
- Linux 复习二
第二章 一.Linux文件系统 1.基本概念 Linux文件系统为单根的树状结构,根为“/”,文件名大小写敏感,除了“/”都是可用字符,文件名以“.”开始的为隐藏文件. 2.常用文件夹 bin:可执行 ...
- Uva 10730 Antiarithmetic?
uva 10730 题意:给出一列数字,如果其中存在长度大于等于3的等差数列,输出no,不存在就输出yes 这道题标定了数列长度n,而且这n个数数据范围是从0到n-1,没有相同的数,这就给我们枚举提供 ...
- C++ - 一个构造函数调用构造函数的问题
今天做C++的实验,题目是写一个二维点的类,然后让一个三维点的类继承它然后扩展.题目是一般学面向对象语言的常用例子. 然后遇到一个这样的问题:之前用Java的时候写构造方法的时 ...
- [K/3Cloud] K/3 Cloud1.0怎样和2.0共存在一台服务器上
第一步:安装Cloud1.0,创建管理中心,创建业务数据中心,备份管理数据库和业务数据库,并且备份安装目录: 第二步:卸载Cloud1.0,清理安装目录,安装Cloud2.0,创建管理中心,创建业务数 ...
- 【BZOJ2434】阿狸的打字机(fail树,DFS序)
题意: 1<=N<=10^5 1<=M<=10^5 输入总长<=10^5 思路: From http://blog.csdn.net/lych_cys/article ...
- spring历史地址
http://repo.spring.io/release/org/springframework/spring/