Codeforces Round #344 (Div. 2) A. Interview 水题
A. Interview
题目连接:
http://www.codeforces.com/contest/631/problem/A
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
Sample Output
22
Hint
题意
给你2*n的矩阵
然后定义一个函数f(a,l,r)表示a数组在l到r的或值
然后让你找到一对l,r,使得f(a,l,r)+f(b,l,r)最大
题解:
由于是或嘛,所以就把所有数全部或起来
代码
#include<bits/stdc++.h>
using namespace std;
long long ans = 0;
int main()
{
int n;
scanf("%d",&n);
long long tmp = 0;
for(int i=1;i<=n;i++)
{
long long x;
scanf("%lld",&x);
tmp|=x;
}
ans+=tmp;
tmp = 0;
for(int i=1;i<=n;i++)
{
long long x;
scanf("%lld",&x);
tmp|=x;
}
ans+=tmp;
cout<<ans<<endl;
}
Codeforces Round #344 (Div. 2) A. Interview 水题的更多相关文章
- Codeforces Round #344 (Div. 2) A. Interview
//http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
随机推荐
- node启动服务
npm install http-server -g http-server ipconfig查看当前ip 手机可访问第一个网址.
- 【Python学习】Jupyter解决单个变量输出问题
使用Jupyter的时候有时候发现,我明明写了好几个变量打印,但是它只显示最后一个.Out只有一个. 但是使用下面的语句.就可以实现多个输出. from IPython.core.interactiv ...
- python基础===时间处理模块
时间模块 Python中有很多方便我们处理时间信息的模块 time 模块 datetime 模块 pytz 模块 dateutil 模块 这里我们着重介绍的是前两种 time模块 time.time( ...
- pam_examples
blank.c /* * $Id$ */ /* Andrew Morgan (morgan@parc.power.net) -- a self contained `blank' * applicat ...
- 文字顺时针旋转90度(纵向)&古诗词排版
1.文字旋转90度 width: 100px; height: 200px; line-height: 100px; text-align: center; writing-mode: vertica ...
- 怎么删除Windows服务
1,首先找到服务名字. 2,在cmd中进到c:下面 3,sc delete 名字. 删除成功
- 步骤一:下载jdk并安装和配置java环境变量
1.下载JDk地址: http://download.eclipse.org/oomph/jre/?vm=1_1_7_0_64_0 2.进入下载页面(下载的是jdk7),点击:Oracle JDK1. ...
- 布隆过滤器 zz
布隆过滤器[1](Bloom Filter)是由布隆(Burton Howard Bloom)在1970年提出的.它实际上是由一个很长的二进制向量和一系列随机映射函数组成,布隆过滤器可以用于检索一个元 ...
- poj 1742(好题,楼天城男人八题,混合背包)
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 33269 Accepted: 11295 Descripti ...
- LocalStorage、SessionStorage使用详解
https://blog.csdn.net/zhongzh86/article/details/55504381