Arab Collegiate Programming Contest 2015 E. The Minions Quiz(思维)

The minions have finally found their new master. This time, he is a Math professor and he is trying veryhard to teach them math. He has been teaching them bitwise operators for over a year! They learnt aboutAND(&) and OR (|) operators and it is time for a quiz to test them. 

The quiz is very simple, they will be given a number A of AND(&) operators, a number B of OR (|)operators and (A + B + 1) integers. They have to find the maximum number that can be obtained byinserting the & and | operators between the given nonnegative integers without changing their order. 

 Finally, there is a special requirement for this quiz, they are required to evaluate the operators from leftto right. 

 Input 

 The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100), followedby T test cases.Each test case will consist of 2 lines. The first line will contain 2 integers A and B (0 ≤ A, B ≤ 10, 000)representing the number of AND(&) and OR (|) operators, respectively. The second line of input willconsist of (A + B + 1) 64-bit nonnegative integers separated by single spaces.

 Output

 For each test case, output a single line containing the maximum number that can be obtained by insertingthe operators between the given integers. 

样例输入复制

2
1 1
1 4 5
2 2
2 3 11 4 5

样例输出复制

5
7

题意:

在a + b + 1个数之间插入 a 个 & 号和 b 个 | 号,问可以得到的最大值

题解:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e4 +10;

int p[N];

int main()
{
    int n, t, a, b;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d", &a, &b);
        n = a + b + 1;
        for(int i = 1; i <= n; ++i)
        {
            scanf("%d", &p[i]);
        }
        ll ans = p[1];
        for(int i = 2; i <= n; ++i)
        {
            if(a)
            {
                ans &= p[i];
                a--;
            }
            else
            {
                ans |= p[i];
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}

 

全部评论

相关推荐

SHC2:春招先狠狠投递,然后你看看能不能申请香港新加坡的一年制master,花不了多少钱,或者现在赶紧去刷一段实习。HR专业考研没必要
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
9225次浏览 83人参与
# 你的实习产出是真实的还是包装的? #
1689次浏览 40人参与
# 巨人网络春招 #
11300次浏览 223人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7416次浏览 42人参与
# 简历第一个项目做什么 #
31519次浏览 327人参与
# 重来一次,我还会选择这个专业吗 #
433317次浏览 3926人参与
# 米连集团26产品管培生项目 #
5648次浏览 214人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186924次浏览 1120人参与
# 牛客AI文生图 #
21402次浏览 238人参与
# 不考虑薪资和职业,你最想做什么工作呢? #
152278次浏览 887人参与
# 研究所笔面经互助 #
118859次浏览 577人参与
# 简历中的项目经历要怎么写? #
309978次浏览 4189人参与
# AI时代,哪些岗位最容易被淘汰 #
63343次浏览 799人参与
# 面试紧张时你会有什么表现? #
30482次浏览 188人参与
# 你今年的平均薪资是多少? #
212996次浏览 1039人参与
# 你怎么看待AI面试 #
179816次浏览 1231人参与
# 高学历就一定能找到好工作吗? #
64302次浏览 620人参与
# 你最满意的offer薪资是哪家公司? #
76425次浏览 374人参与
# 我的求职精神状态 #
447969次浏览 3128人参与
# 正在春招的你,也参与了去年秋招吗? #
363209次浏览 2637人参与
# 腾讯音乐求职进展汇总 #
160568次浏览 1110人参与
# 校招笔试 #
470199次浏览 2962人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务