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(ai ,aj) 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≤100000), indicating the length of the sequence.

The second line contains n integers: a​1​​ ,a​​2​ ,...,a​n(1≤ai≤10的9次方), indicating the sequence.

It is guaranteed that the sum of n in all cases does not exceed 100000.

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

题意,求在a数组中找出s子集,要求子集中任意两个数异或之后比这两个数都小,求最大子集里面元素的个数

可以知道,2进制的0和1 才是1,其他是0,要求两个数异或要更小,则必须两个数二进制的最高位要都是1,所以,只需要知道在每个长度的二进制区间中,存在多少个数字,数字最多的那个就是答案

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+10;
int a[N];
int upp[32];//区间上限
int doww[32];//区间下限
void init()
{
int x=2;
upp[0]=1;
doww[0]=1;
rep(i,1,32)
{
doww[i]=x;
upp[i-1]=x-1;
x*=2;
}
upp[31]=x-1;
}
int num[32];//存每个区间的数量
int main()
{
int re;scf(re);
init();
while(re--)
{
mm(num,0);
int n;scf(n);
rep(i,0,n)
{
scf(a[i]);
rep(j,0,32)
{
if(a[i]>=doww[j]&&a[i]<=upp[j])
{
num[j]++;
break;
}
}
}
int ans=0;
rep(i,0,32)
ans=max(ans,num[i]);
prf(ans);
}
return 0;
}

K XOR Clique的更多相关文章

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

  2. XOR Clique(按位异或)

    XOR Clique(按位异或): 传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4057 准备:异或:参加运算的两 ...

  3. ZOJ 4057 XOR Clique(位运算)

    XOR Clique BaoBao has a sequence a​1​,a​2,...,a​n. He would like to find a subset S of {1,2,...,n} s ...

  4. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online Solution

    A    Live Love 水. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; const i ...

  5. The 2018 ACM-ICPC Asia Qingdao Regional Contest(青岛网络赛)

    A Live Love 水 #include <algorithm> #include<cstdio> #include<cstring> using namesp ...

  6. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online

    A Live Love DreamGrid is playing the music game Live Love. He has just finished a song consisting of ...

  7. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online(2018 青岛网络预选赛)

    A题 A Live Love 原题链接:https://pintia.cn/problem-sets/1036903825309761536/problems/1041155943483625472 ...

  8. Atcoder Beginner Contest 121 D - XOR World(区间异或和)

    题目链接:https://atcoder.jp/contests/abc121/tasks/abc121_d 题目很裸(Atcoder好像都比较裸 就给一个区间求异或和 n到1e12 肯定不能O(n) ...

  9. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 xor (根号分治)

    xor There is a tree with nn nodes. For each node, there is an integer value a_ia​i​​, (1 \le a_i \le ...

随机推荐

  1. Hibernate非主键关联

    一. 非主键关联,我们进行外键关联时,通常使用的是主键,但有时候需要使用到其他列时可以通过以下方法设置: 注解中:@JoinColumn(name="city", referenc ...

  2. Codefoces909E Coprocessor(拓扑排序)

    http://codeforces.com/problemset/problem/909/E 由于分了两个queue,所以push的时候可以统一操作,不会影响彼此.两个queue相当于是平等的,只是q ...

  3. pygame-KidsCanCode系列jumpy-part7-游戏启动/结束画面

    通常一个游戏启动(start)或结束(game over)时,都会显示一个画面,来引导用户.这节,我们学习如何处理这块逻辑. 其实之前,我们已经预留了2个函数,只要把它实现即可: def show_s ...

  4. JAVA:测试java虚拟机支持的最大内存 Xmx 值?Tomcat 内存溢出?(转)

    如下命令,即可测试:不断调整n的值,windows上32位的1.6x为: 1610m java -Xmx1610M -versionjava -Xmx1610m -version 网摘的tomcat内 ...

  5. oracle操作字符串:拼接、替换、截取、查找、长度、判断

    1.拼接字符串 1)可以使用“||”来拼接字符串 select '拼接'||'字符串' as str from dual 2)通过concat()函数实现 select concat('拼接', '字 ...

  6. C# 枚举类型 enum

    我个人感觉平日用到的enum应该是非常简单的,无非就是枚举和整数.字符串之间的转换.最近工作发现一些同事居然不太会用这个东东,于是就整理一下. 枚举类型是定义了一组“符号名称/值”配对.枚举类型是强类 ...

  7. InfluxDB meta文件解析

    操作系统 : CentOS7.3.1611_x64 go语言版本:1.8.3 linux/amd64 InfluxDB版本:1.1.0 influxdb默认配置: /etc/influxdb/infl ...

  8. PHP异步扩展Swoole笔记(2)

    dispatch_mode, 数据包分发策略 可以选择7种类型,默认为21,轮循模式,收到会轮循分配给每一个Worker进程2,固定模式,根据连接的文件描述符分配Worker.这样可以保证同一个连接发 ...

  9. java写桌面程序

    一:使用java swing开发窗口程序 简述: 1.文章内容主要是使用java swing类库开发一个小的窗口程序,然后使用exe4j发布成exe可以安装的程序,让初学者对使用java来做pc软件开 ...

  10. CentOS 7 使用 ACL 设置文件权限

    Linux  系统标准的 ugo/rwx 集合并不允许为不同的用户配置不同的权限,所以 ACL 便被引入了进来,为的是为文件和目录定义更加详细的访问权限,而不仅仅是这些特别指定的特定权限. ACL 可 ...