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 ...
随机推荐
- linux内核启动分析(3)
主要分析do_basic_setup函数里面的do_initcalls()函数,这个函数用来调用所有编译内核的驱动模块中的初始化函数. static void __init do_initcalls( ...
- Filecoin:一种去中心化的存储网络(一)
开始初步了解学习Filecoin,如下是看白皮书的内容整理. 参考: 白皮书中文版 http://chainx.org/paper/index/index/id/13.html 白皮书英文版 http ...
- node.js2
同步是指:同步阻塞操作,异步是指:异步非阻塞操作. 第一部分:fs模块 1.引入fs模块 require('fs'); 2.写文件 01.异步写:writeFile fs.writeFile(path ...
- Leetcode 之Binary Tree Postorder Traversal(47)
中序遍历二叉搜索树,得到的是一个有序的结果,找出其中逆序的地方就可以了.如果逆序的地方相邻,只需把逆序的相换即可:如果不相邻,则需要找到第二个逆序对的 第二个元素再做交换. 定义两个指针p和q来指定需 ...
- Linux Python apache的cgi配置
一.找到安装Apache的目录/usr/local/apache2/conf,并对httpd.conf配置文件进行修改 1.加载cgi模块 去掉注释: LoadModule cgid_module m ...
- 面试题之实现系统函数系列一:实现memmove函数
编译环境 本系列文章所提供的算法均在以下环境下编译通过. [算法编译环境]Federa 8,linux 2.6.35.6-45.fc14.i686 [处理器] Intel(R) Core(TM)2 Q ...
- POJ-1681
Painter's Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4839 Accepted: 2350 ...
- es6中对象的一些操坐
变量的赋值 key值得构建 对象的严格检测 对象的合并 1.变量的赋值: let name='宋宇',age='17岁': let obj={name,age} //快速的将变量引入到对象中去. 2. ...
- shopnc 店铺二级分类添加商品
$class_2 = $goods_class[$gc_id]['gc_parent_id']; $class_1 = $goods_class[$class_2]['gc_parent_id']; ...
- eclipse 查看jdk源码
eclipse中引入jdk源码的设置: 设置: 1.点 "window"-> "Preferences" -> "Java" ...