2018 ACM-ICPC 亚洲青岛区域网络赛 K XOR Clique

BaoBao has a sequence a​1​​,a​2​​,...,a​n​​. He would like to find a subset Sof {1,2,...,n} such that ∀i,j∈S, a​i​​⊕a​j​​<min(a​i​​,a​j​​) and ∣S∣ is maximum, where ⊕ means bitwise exclusive or.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1≤n≤10​5​​), indicating the length of the sequence.

The second line contains n integers: a​1​​,a​2​​,...,a​n​​ (1≤a​i​​≤10​9​​), indicating the sequence.

It is guaranteed that the sum of n in all cases does not exceed 10​5​​.

Output

For each test case, output an integer denoting the maximum size of S.

Sample Input

3
3
1 2 3
3
1 1 1
5
1 2323 534 534 5

Sample Output

2
3
2

作者: 浙江大学竞赛命题组

单位: ACMICPC

时间限制: 500 ms

内存限制: 64 MB

代码长度限制: 32 KB

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
    int t, n, x;
    scanf("%d", &t);
    while(t--)
    {
        int a[30] = {0};
        scanf("%d", &n);
        while(n--)
        {
            scanf("%d", &x);
            int y = 0;
            while(x > 1)
            {
                y++;
                x /= 2;
            }
            a[y]++;
        }
        int maxn = *(max_element(a, a+30));
        printf("%d\n", maxn);

    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40763929/article/details/82747455