CF-631-.Interview-水题

news/2024/7/5 20:18:14

A.Interview
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit

Status

Practice

CodeForces 631A
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
Input
5
1 2 4 3 2
2 3 3 12 1
Output
22
Input
10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6
Output
46
Hint
Bitwise OR of two non-negative integers a and b is the number c = aORb, 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, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4 OR 3) + (3 OR 3OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose l = 1 and r = 4, l = 1 and r = 5, l = 2 and r = 4, l = 2 andr = 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.

其实水题一道,但是由于开始并没搞懂位运算的性质没读懂题/(ㄒoㄒ)/~~
两个数进行位运算的结果是不会减少的,所以最大的值只需要将所有位运算的和加起来即可;

using namespace std;  
typedef long long LL;
int a[1005],b[1005];
int n;
int suma=0;
int sumb=0;
int main() //二进制或运算只增不减 
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i<n;i++)
    {
        suma=suma|a[i];
        sumb=sumb|b[i];
    }
    cout<<suma+sumb<<endl;
    return 0;   
}

仅代表个人观点,欢迎交流探讨,勿喷~~~

这里写图片描述

PhotoBy:WLOP

http://weibo.com/wlop


http://www.niftyadmin.cn/n/2246215.html

相关文章

ntp多台主机时间同步

通俗的讲&#xff0c;多台主机ntp时间同步&#xff0c;就是自定义集群中一台机器&#xff08;我们这里叫它server&#xff09;与网络时间同步&#xff0c;然后其它主机与server主机时间同步 另外&#xff0c;ntp时间同步机制不是我们想象的那样直接同步&#xff0c;而是“逐渐”…

5G已来,5G精品系列课免费送?

5G不再只是从2G.txt到3G.jpg再到4G.avi的网络速率的提升&#xff0c;而是将人与人之间的通信扩展到万物互联&#xff0c;打造全移动和全连接的数字化社会。 众所周知&#xff0c;2018年6月中旬&#xff0c;3GPP全会批准通过了5G NR独立组网(SA)规范标准。全球各电信厂商和运营商…

Java大数简单题---Yet another A + B

PracticeGym 100735I Description Statements You are given three numbers. Is there a way to replace variables A, B and C with these numbers so the equality A  B  C is correct? Input There are three numbers X1, X2 and X3 (1 ≤ Xi ≤ 10100), each…

Cisco HyperFlex 多区域上联(Disjoint Networks Upstream)

Cisco HyperFlex 多区域上联&#xff08;Disjoint Networks Upstream&#xff09;Deploy Layer 2 Disjoint Networks Upstream in End Host Mode for HyperFlex一般意义上的HX平台是部署在大二层环境中&#xff0c;不同vlan跑不同的功能&#xff08;data&#xff0c;mgt&#x…

Restore 数学题,水题(转)

C - Restore Time Limit:25000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100735E Description standard input/output Statements Given a matrix A of size N * N. The rows are numbered from 0 to N-1, the column…

unity实战 手机屏幕适配

使用背景 为了在UI中使用特效层&#xff0c;项目Canvas采用了Screen Space-Camera类型 UI的Scale Mode 选择的是Scale With Screen Size 的Expand&#xff0c;画布大小填的是1334, 750 在该选择下&#xff0c;会自动根据分辨率适配宽度/高度。 自动适配的规则是&#xff1a; 屏…

八皇后问题---递归回溯

每次需要满足的条件&#xff1a;abs(x[j]-x[k])abs(j-k) || x[j]x[k] #include <iostream> #include <cmath> using namespace std; const int num8; int sum0; int x[num]{0}; bool place (int k) {for(int j1;j<k;j){if(abs(x[j]-x[k])abs(j-k)||x[j]x[k])re…

容器监控实践—cAdvisor

概述 为了解决docker stats的问题(存储、展示)&#xff0c;谷歌开源的cadvisor诞生了&#xff0c;cadvisor不仅可以搜集一台机器上所有运行的容器信息&#xff0c;还提供基础查询界面和http接口&#xff0c;方便其他组件如Prometheus进行数据抓取&#xff0c;或者cadvisor inf…