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

本文介绍了一个关于2*n矩阵的问题,目标是通过计算特定的或值来找到使两个数组的或值之和最大的一对索引。文章提供了一种直接计算的方法,并给出了完整的C++代码实现。

题意:

给你2*n的矩阵

然后定义一个函数f(a,l,r)表示a数组在l到r的或值

然后让你找到一对l,r,使得f(a,l,r)+f(b,l,r)最大

思路:

直接或所有数

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #include<cstdlib>
 6 #include<string>
 7 #include<cmath>
 8 #include<vector>
 9 using namespace std;
10 const int maxn=1e5+7;
11 const double eps=1e-8;
12 const double pi=acos(-1);
13 #define ll long long
14 const int MOD = 10000;
15 
16 int n;
17 
18 int main()
19 {
20     scanf("%d",&n);
21     ll ans=0;
22     ll x=0;
23     for(int i=0; i<n; i++)
24     {
25         ll y;
26         scanf("%I64d",&y);
27         x|=y;
28     }
29     ans+=x;
30     x=0;
31     for(int i=0; i<n; i++)
32     {
33         ll y;
34         scanf("%I64d",&y);
35         x|=y;
36     }
37     ans+=x;
38     printf("%I64d\n",ans);
39     return 0;
40 }
View Code

 

转载于:https://www.cnblogs.com/ITUPC/p/5243785.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值