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

Posted fqfzs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The 2018 ACM-ICPC Asia Qingdao Regional Contest K XOR Clique相关的知识,希望对你有一定的参考价值。

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,jS, 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 (1n10?5??), indicating the length of the sequence.

The second line contains n integers: a?1??,a?2??,...,a?n?? (1a?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
",maxx);
36     }
37     return 0;
38 }

 









以上是关于The 2018 ACM-ICPC Asia Qingdao Regional Contest K XOR Clique的主要内容,如果未能解决你的问题,请参考以下文章

The 2018 ACM-ICPC Asia Qingdao Regional Contest

The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online J Press the Button

The 2018 ACM-ICPC Asia Beijing Regional Contest

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

The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online - H Traveling on the Axis-思维模拟题目

I. Distance (模拟)2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest