码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-09-16 19:40:16      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:mem   sample   二进制   htm   signed   multi   eset   contains   sequence   

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\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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!