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;
}

 

全部评论

相关推荐

03-05 16:22
已编辑
西安邮电大学 Web前端
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
6395次浏览 61人参与
# 你的实习产出是真实的还是包装的? #
1304次浏览 32人参与
# 米连集团26产品管培生项目 #
4719次浏览 206人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7077次浏览 37人参与
# 简历第一个项目做什么 #
31329次浏览 315人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186521次浏览 1115人参与
# 巨人网络春招 #
11213次浏览 223人参与
# 研究所笔面经互助 #
118787次浏览 577人参与
# 面试紧张时你会有什么表现? #
30416次浏览 188人参与
# 简历中的项目经历要怎么写? #
309572次浏览 4163人参与
# 职能管理面试记录 #
10722次浏览 59人参与
# AI时代,哪些岗位最容易被淘汰 #
62719次浏览 748人参与
# 网易游戏笔试 #
6374次浏览 83人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
6993次浏览 154人参与
# 腾讯音乐求职进展汇总 #
160437次浏览 1107人参与
# 从哪些方向判断这个offer值不值得去? #
56712次浏览 357人参与
# 正在春招的你,也参与了去年秋招吗? #
362741次浏览 2632人参与
# 你怎么看待AI面试 #
179417次浏览 1182人参与
# 小红书求职进展汇总 #
226905次浏览 1357人参与
# 你的房租占工资的比例是多少? #
92146次浏览 896人参与
# 校招笔试 #
467654次浏览 2954人参与
# 经纬恒润求职进展汇总 #
155713次浏览 1085人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务