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 ...
随机推荐
- PHPExcel导入
PHPExcel 是用来操作Office Excel 文档的一个PHP类库,可以使用它来读取.写入不同格式的电子表格 Github:https://github.com/PHPOffice/PHPEx ...
- vue基础---实例
(1)数据和方法 ①响应式双向绑定 当一个 Vue 实例被创建时,它向 Vue 的响应式系统中加入了其 data 对象中能找到的所有的属性.当这些属性的值发生改变时,视图将会产生“响应”,即匹配更新为 ...
- string 字符串--------redis
APPEND 语法:APPEND KEY VALUE 如果key已经存在并且是一个字符串,append 命令将value追加到key原来的值的末尾. 如果key不存在,append就简单地将给定key ...
- 关于Extjs的窗口拖拽,改变大小,背景淡化问题
大部分Extjs的Windows问题:在Extjs4代码中,只要加几句话: frame:true, //这个窗口的边边是圆的 border : false , //窗口没有边框 draggable: ...
- nginx代理标准配置
#nginx开启的进程数worker_processes 4; #4核CPU #定义全局错误日志定义类型,[debug|info|notice|warn|crit]error_log ...
- CentOS 6磁盘配额
可以指定用户能超过其配额限制.如果不想拒绝用户对卷的访问但想跟踪每个用户的磁盘空间使用情况,启用配额而且不限制磁盘空间的使用是非常有用的.也可指定不管用户超过配额警告级别还是超过配额限制时是否要记录事 ...
- CCF201604-1 折点计数 java(100分)
试题编号: 201604-1 试题名称: 折点计数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定n个整数表示一个商店连续n天的销售量.如果某天之前销售量在增长,而后一天 ...
- HDU 5115 (2014ACM/ICPC亚洲区北京站) D题(Dire Wolf)
题目传送门 设dp[i][j]为杀掉区间i到j之间的狼需要付出的最小代价,那么dp[i][j]=min{dp[i][k-1]+dp[k+1][j]+a[k]+b[i-1]+b[j+1]} Java代码 ...
- PAT 1145 Hashing - Average Search Time
The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...
- 泛型约束 ---类型参数上的限制(where T:class,new())
今天遇到的一个问题,找到了解决办法,收藏以后记得看一下!