题解:P10696 [SNCPC2024] 写都写了,交一发吧

· · 题解

简化版题意

在序列 g 中寻找两个数 i,j,使得 g_i \operatorname{and} g_j 的值最大,并输出 g_i \operatorname{and} g_j 的值。

思路

设有以下条件:

因为在 y \le x 的数据范围中,只有 x 与其本身的每一个二进制位均相同,所以 y = x。\ 同理,由于 x \operatorname{and} x = x,因此我们只需要找到每一组数中的最大值并输出即可。

代码

我们根据以上的思路,得到以下的代码:

#include <iostream>
using namespace std;
void work()
{
    int n;
    cin >> n;
    int yyy;
    int ans = 0;
    while(n--)
    {
        cin >> yyy;
        ans = max(ans,yyy);
    }
    cout << ans << endl;
}
int main()
{
    int t;
    cin >> t;
    while(t--) work();
    return 0;
}