codeforces 631A Interview
1 second
256 megabytes
standard input
standard output
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.
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).
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
- 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
Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1if 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, becausef(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 choosel = 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.
题意:给两个序列,要求找到一个区间(l,r)使得在这个区间内序列a的数相互或运算和序列b的数或运算之后和最大,输出最大和
题解:题目中的区间就是一个误导项,因为是或运算,遇见1即为1所以我们把序列中所有数或运算即可
- #include<stdio.h>
- #include<string.h>
- #include<string>
- #include<math.h>
- #include<algorithm>
- #define LL long long
- #define PI atan(1.0)*4
- #define DD double
- #define MAX 300100
- #define mod 100
- #define dian 1.000000011
- #define INF 0x3f3f3f
- using namespace std;
- char s[MAX];
- int a[MAX],b[MAX];
- int main()
- {
- int n,i,j;
- while(scanf("%d",&n)!=EOF)
- {
- for(i=1;i<=n;i++)
- scanf("%d",&a[i]);
- for(i=1;i<=n;i++)
- scanf("%d",&b[i]);
- int x=a[1];
- int y=b[1];
- for(i=2;i<=n;i++)
- {
- x=max(x,(x|a[i]));
- y=max(y,(y|b[i]));
- }
- printf("%d\n",x+y);
- }
- return 0;
- }
codeforces 631A Interview的更多相关文章
- Codeforces 631A Interview【模拟水题】
题意: 模拟模拟~~ 代码: #include<iostream> using namespace std; const int maxn = 1005; int a[maxn], b[m ...
- codeforces 631A A. Interview
A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- CodeForces 738A Interview with Oleg
模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...
- HPU周赛题目解析
A - Wilbur and Swimming Pool Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Codeforces--631A--Interview(位运算)
Interview Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:262144KB ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- Codeforces Round #344 (Div. 2) A. Interview 水题
A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #344 (Div. 2) A. Interview
//http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...
随机推荐
- JS创建类以及类的方法(StringBuffeer类)
创建StringBuffer类以及toString,append()方法 //创建一个StringBuffer类 ,此类有两个方法:一个是append方法一个是toString方法 function ...
- poj 2029 Get Many Persimmon Trees (dp)
题目链接 又是一道完全自己想出来的dp题. 题意:一个w*h的图中,有n个点,给一个s*t的圈,求这个圈能 圈的最多的点 分析:d[i][j]代表i行j列 到第一行第一列的这个方框内有多少个点, 然后 ...
- codeforces 340A The Wall(简单数学题)
题意:输入a,b,x,y,a,b分别是两人的步数(每a块砖,刷一次),则有一些砖被两人同时刷到了,问[x,y]区间内有多少块砖同时被两人刷到. 分析:就是求[x,y]中有多少个能把a,b的最小公倍数l ...
- codevs 1137 计算系数
什么时候NOIP也要出二项式定理了? 二项式定理+逆元. #include<iostream> #include<cstdio> #include<cstring> ...
- Struts2中date标签乱码问题解决
1.出现的问题如下图 八月份以前没有问题,但从九月份开始就会出现乱码问题 2.开始解决 (1)在使用标签的JSP中加入: <%@taglib prefix="s" uri=& ...
- @section Right
布局页 _BaseLayout.cshtml @RenderSection("Right", true) 视图页 Index.cshtml @{ Layout = "~/ ...
- why dicePlayer cannot player with defy mb526
硬件加速视频播放器 DicePlayer v2.0.38 ... ..... ...... ........ \ 局限性:- 视频兼容性依赖于您设备的视频硬解码能力
- hadoop2.0中无法启动datanode的问题
问题描述:在启动datanode进程时,能成功的启动:但用jps查看进程时,发现进程不存在,下面是在datanode日记文件的错误信息 如下图的截屏所示: 主要原因:发生错误的原因:由于把data放在 ...
- lightoj 1023
题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs. #include<cstdio> #include<string> #include<cstrin ...
- Bug疑难杂症 - java.lang.NoSuchFieldError: udhLen
通过友盟后台记录到一个诡异的错误: HUAWEI C8825D 4.0.4 百度.谷歌都未能找到一丝结果更别提解决方案. java.lang.NoSuchFieldError: udhLen at a ...