The 2018 ACM-ICPC Asia Qingdao Regional Contest【 K XOR Clique】

XOR Clique


Time Limit: 1 Second      Memory Limit: 65536 KB


BaoBao has a sequence . He would like to find a subset  of  such that ,  and  is maximum, where  means bitwise exclusive or.

Input

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

The first line contains an integer  (), indicating the length of the sequence.

The second line contains n integers:  (), indicating the sequence.

It is guaranteed that the sum of  in all cases does not exceed .

Output

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

Sample Input

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

Sample Output

2
3

题解:给定 n 个整数,求一个集合,是的集合中的任意两个数的异或值小于这两个数。很容易发现当且仅当两个数字最高位二进制相同的时候才满足条件,即为相同二进制最高位的数字数量。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[33];
int main() {
	int t, n;
	scanf("%d", &t);
	while(t--) {
        scanf("%d", &n);
        int x;
        memset(a, 0, sizeof a);
        for(int i = 0; i < n; i++) {
            scanf("%d", &x);
            int cnt = 0;
            while(x > 0) {
                x/=2;
                cnt++;
            }
            a[cnt]++;
        }
        sort(a,a+33);
        reverse(a,a+33);
        printf("%d\n", a[0]);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值