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

The 2018 ACM-ICPC Asia Qingdao Regional Contest K XOR Clique的相关文章

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 (Gym - 102082)

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 A - Digits Are Not Just Characters 签到. B - Arithmetic Progressions 题意:从给定的集合中选出最多的数构成等差数列. 题解:数字排序后,设\(dp[i][j]\)表示等差数列最后一个数字为\(a[i]\),倒数第二个数字为\(a[j]\)的最大个数.然后对于每一位枚举 \(i\),\(lower\_bound()\)找有无合法的

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Krak&#243;w

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik's RectangleProblem B: What does the fox say?Problem C: Magical GCDProblem D: SubwayProblem E: EscapeProblem F: DraughtsProblem G: History courseProblem H: C

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

H Traveling on the Axis 作者: 浙江大学竞赛命题组 单位: ACMICPC 时间限制: 500 ms 内存限制: 64 MB 代码长度限制: 32 KB 传送门 BaoBao is taking a walk in the interval [0,n] on the number axis, but he is not free to move, as at every point (i−0.5) for all i∈[1,n], where i is an intege

2018 ICPC Asia Jakarta Regional Contest

题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . . . Ο . . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thinking:kk pai爷 Code:kk 不能直接反转,比如"010101",直接反转后就变成"101010",右移一位,然后加个0就可以了. 所以要先统计01的数量,如果0大于1,就全变成1,1大于0,就全变成0(从数量上的改变就大于s/2了),相等的话,就看首位是0

The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online

XOR Clique Press the Button Kuririn MIRACLE Traveling on the Axis Couleur Chaleur Infinite Parenthesis Sequence Pixel Art Halting Problem Red Black Tree Live Love 原文地址:https://www.cnblogs.com/Accpted/p/11298226.html

2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings

As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC Jakarta is planning to build two new buildings. These buildings should have a shape of a rectangle of the same size. Now, their problem is to find lan

2019-2020 ICPC, Asia Jakarta Regional Contest C. Even Path

Pathfinding is a task of finding a route between two points. It often appears in many problems. For example, in a GPS navigation software where a driver can query for a suggested route, or in a robot motion planning where it should find a valid seque

2018-2019 ACM-ICPC, Asia Seoul Regional Contest K TV Show Game 2-sat

题目传送门 题意: 有n个人,k盏灯,灯有红蓝两种颜色,每个人都猜了三种灯的颜色,问如何安排灯的颜色,使得每个人猜的灯至少有两个是对的. 思路: 很容易想到2-sat,但是显然枚举每个人猜对的情况是不显示的,因为猜对两个和猜对三个两种情况就很难搞了.所以我们枚举每一个人猜的灯错的是哪一盏,如果某一盏错了,那么另外两盏就必须是对的,这样才符合条件. 我们用一个light的二维vector,保存:$灯的某种颜色,选这个颜色是属于选错的人$,再用一个二维vector名字叫people保存每个人的三种错

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri