K XOR Clique
BaoBao has a sequence a?1??,a?2??,...,a?n??. He would like to find a subset S of {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
给出n个数字,要求输出一个最长集合的长度,在这个集合中任意两个数两两异或后结果比原来小相当于集合中每个数的二进制形式长度相等
1 #include<bits/stdc++.h> 2 using namespace std; 3 int s[3000]; 4 int bit_width(unsigned int n) 5 { 6 unsigned int i = 0; 7 8 do { 9 ++i; 10 } while ((n >> i)); 11 12 return i; 13 } 14 int main() 15 { 16 int t; 17 scanf("%d",&t); 18 while(t--) 19 { 20 int n,a; 21 scanf("%d",&n); 22 memset(s,0,sizeof(s)); 23 int len1,len2,num=0,maxx=0; 24 for(int i=0;i<n;i++) 25 { 26 scanf("%d",&a); 27 len1=bit_width(a); 28 s[len1]++; 29 30 } 31 for(int i=0;i<3000;i++) 32 { 33 maxx=max(maxx,s[i]); 34 } 35 printf("%d\n",maxx); 36 } 37 return 0; 38 }
原文地址:https://www.cnblogs.com/fqfzs/p/9656928.html
时间: 2024-10-29 15:24:20