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 水题的更多相关文章

  1. Codeforces Round #344 (Div. 2) A. Interview

    //http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...

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

  3. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  4. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  5. Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

  6. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  7. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  8. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  9. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

随机推荐

  1. python中BeautifulSoup模块

    BeautifulSoup模块是干嘛的? 答:通过html标签去快速匹配标签中的内容.效率相对比正则会好的多.效率跟xpath模块应该差不多. 一:解析器: BeautifulSoup(html,&q ...

  2. 【EverydaySport】健身笔记——动态牵拉

    动态牵拉,包含了动态和牵拉两个概念.动态牵拉要求牵拉的过程要伴随着走路,即行进中牵拉,动态牵拉不仅可以使得肌肉得到延展,还可以激活肌肉协同工作,发展协调性.灵活性.进行动态牵拉时每个动作要进行5~10 ...

  3. 禁用 Cortana 的解决办法

    1. GPedit.msc 2. 然后在本地组策略编辑器中,点击“用户配置”中的“管理模版”,接着双击右侧的“Windows 组件”. 3. 下拉滚动条,并找到“文件资源管理器”,双击进入. 找到“在 ...

  4. 一个无线通信类投稿的期刊list

    转载一个,但是有些期刊的影响因子不是很对,要投的时候还是再到期刊主页上面看一看吧~ 期刊缩写 期刊全名 近年影响因子 P IEEE Proceedings Of The IEEE 3.686 IEEE ...

  5. python一步高级编程

    1.==,is的使用 总结 ·is是比较两个引用是否指向了同一个对象(引用比较). ·==是比较两个对象是否相等. 2.深拷贝.浅拷贝 1.浅拷贝 浅拷贝是对于一个对象的顶层拷贝 通俗的理解是:拷贝了 ...

  6. linux命令--head

    head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 具体使用参考链接: h ...

  7. NOIP 2011 Day 1

    NOIP 2011 Day 1 tags: NOIP 搜索 categories: 信息学竞赛 总结 铺地毯 选择客栈 Mayan游戏 铺地毯 Solution 因为只会询问一个点被谁覆盖, 而且后面 ...

  8. [水煮 ASP.NET Web API2 方法论](12-4)OData 支持的 Function 和 Action

    问题 在 Web API 中使用 OData Function 和 Action. 解决方案 可以通过 ODataModelBuilder,使用 OData 构建 ASP.NET Web API, E ...

  9. canvas时钟效果

    话不多说,直接上代码 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/x ...

  10. HDU 1097.A hard puzzle-快速幂/取模

    快速幂: 代码: ll pow_mod(ll a,ll b){      ll ans=;      while(b){          ==){              ans=ans*a%mo ...