标签:mem sample 二进制 htm signed multi eset contains sequence
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.
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??.
For each test case, output an integer denoting the maximum size of S.
3
3
1 2 3
3
1 1 1
5
1 2323 534 534 5
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 }
The 2018 ACM-ICPC Asia Qingdao Regional Contest K XOR Clique
标签:mem sample 二进制 htm signed multi eset contains sequence
原文地址:https://www.cnblogs.com/fqfzs/p/9656928.html