codeforces 631A A. 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 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, 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 choose l = 1 andr = 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]内ai的or和bi的or和的最大值;
思路:暴力求任意的l到r的要求值,再找出最大的输出;
AC代码:
#include <bits/stdc++.h>
using namespace std;
long long a[1003],b[1003],fa[1003][1003],fb[1003][1003];
int n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
cin>>b[i];
}
long long x,y;
for(int i=1;i<=n;i++)
{
fa[i][i]=a[i];
fb[i][i]=b[i];
for(int j=i+1;j<=n;j++)
{
fa[i][j]=(fa[i][j-1]|a[j]);
fb[i][j]=(fb[i][j-1]|b[j]);
}
}
long long ans=0;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
ans=max(ans,fa[i][j]+fb[i][j]);
}
}
cout<<ans<<"\n";
return 0;
}
codeforces 631A A. Interview的更多相关文章
- 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 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- 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 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 ...
- CodeForces 738A Interview with Oleg
模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...
随机推荐
- windows上mysql安装
1. 下载MySQL Community Server 5.7.14 Index of /MySQL/Downloads/MySQL-Cluster-7.1 2. 解压MySQL压缩包 安装路径:E: ...
- Android使用JUnit进行单元测试
前言:为什么要进行单元测试?单元测试能快速是开发者,找到代码中的问题所在,因为是单元测试,所以代码只执行响应的测试单元,执行快解决问题的效率高,同时提高代码的质量. Android中的单元测试可简单分 ...
- thinkPHP5.0的学习研究【架构】
2017年6月19日18:51:53 架构:1.ThinkPHP5.0应用基于MVC(模型-视图-控制器)的方式来组织.2.MVC是一个设计模式,它强制性的使应用程序的输入.处理和输出分开.使用MVC ...
- Collective Mindsets (medium) (逻辑题)
B - Collective Mindsets (medium) Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I6 ...
- 3.设计模式----TemplateMethod模式
模板模式,其实是一种思想,在开发中有很多地方用到模板,因为毕竟我们不可能每一个都一出一段!一个模板,填充不同,出来效果也是不一样! 准备画个时序图的,没找到工具,过几天补上! 模板模式在出现bug时候 ...
- rpc接口和http接口的区别和联系
1 什么是http接口 http接口是基于http协议的post和get接口. 2 什么是rpc接口 rpc接口就相当于调用本地接口一样调用远程服务的接口. 3 常用的rpc框架 thrift 自动代 ...
- swift 使用运行时进行属性关联
1.用OC思想写swift代码真得很爽,swift需要的OC基本上都有,只不过略微改变了一下,例如以前的Foundation库前缀NS全部去掉了,等等...思想其实都一样,不过swift确实非常精简, ...
- [ArcGIS]Oracle RAC下创建地理数据库(Create Enterprise Geodatabase)失败的解决方法
转载请注明原文地址:http://www.cnblogs.com/litou/p/8028843.html 环境:Oracle 11g 11.2.0.1.0(双节点RAC群集),ArcGIS Desk ...
- 【TFS】解决TFS编译中文乱码问题
前言; TFS2018做程序集成非常方便,线上编译然后直接生成docker镜像,但是在使用过程中遇到编译窗口中文乱码的问题,这个问题找了好久没人知道怎么解决.如下: 这个问题不解决,每次编译失败,研发 ...
- Arduino 看门狗使用
1.需要调用 #include <avr/wdt.h> 2.设置看门狗复位时间 wdt_enable(WDTO_2S); 代码时间定义的底层查看 #define WDTO_15MS 0 / ...