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,所以,只需要知道在每个长度的二进制区间中,存在多少个数字,数字最多的那个就是答案

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include <iomanip>
  5. #include<cmath>
  6. #include<float.h>
  7. #include<string.h>
  8. #include<algorithm>
  9. #include<vector>
  10. #include<queue>
  11. #define sf scanf
  12. #define pf printf
  13. #define scf(x) scanf("%d",&x)
  14. #define scff(x,y) scanf("%d%d",&x,&y)
  15. #define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
  16. #define prf(x) printf("%d\n",x)
  17. #define mm(x,b) memset((x),(b),sizeof(x))
  18. #define rep(i,a,n) for (int i=a;i<n;i++)
  19. #define per(i,a,n) for (int i=a;i>=n;i--)
  20. typedef long long ll;
  21. const ll mod=1e9+7;
  22. const double eps=1e-8;
  23. const int inf=0x3f3f3f3f;
  24. using namespace std;
  25. const double pi=acos(-1.0);
  26. const int N=1e5+10;
  27. int a[N];
  28. int upp[32];//区间上限
  29. int doww[32];//区间下限
  30. void init()
  31. {
  32. int x=2;
  33. upp[0]=1;
  34. doww[0]=1;
  35. rep(i,1,32)
  36. {
  37. doww[i]=x;
  38. upp[i-1]=x-1;
  39. x*=2;
  40. }
  41. upp[31]=x-1;
  42. }
  43. int num[32];//存每个区间的数量
  44. int main()
  45. {
  46. int re;scf(re);
  47. init();
  48. while(re--)
  49. {
  50. mm(num,0);
  51. int n;scf(n);
  52. rep(i,0,n)
  53. {
  54. scf(a[i]);
  55. rep(j,0,32)
  56. {
  57. if(a[i]>=doww[j]&&a[i]<=upp[j])
  58. {
  59. num[j]++;
  60. break;
  61. }
  62. }
  63. }
  64. int ans=0;
  65. rep(i,0,32)
  66. ans=max(ans,num[i]);
  67. prf(ans);
  68. }
  69. return 0;
  70. }

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. ubuntu17.04 调试系统工具bcc,systamtap安装

    发行版 ubuntu17.04 cat lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=17.04 DISTRIB_CODENAME=zesty DISTR ...

  2. 【独家】硅谷创业公司在中国常跌的五个坑|禾赛科技CEO李一帆柏林亚太周主题演讲

    [独家]硅谷创业公司在中国常跌的五个坑|禾赛科技CEO李一帆柏林亚太周主题演讲 李一帆 Xtecher特稿作者 关注  Xtecher推荐   演讲者:李一帆   翻译:晓娜   网址:www.xt ...

  3. 开源GIS浅谈 【转】

    http://blog.csdn.net/happyduoduo1/article/details/51773850 谈到GIS软件,首先让我们想到的是GIS界的龙头大哥ESRI公司旗下的ArcGIS ...

  4. 先打11.2.0.3.8这个PSU,后建库

    SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; Session altered. SQL> select c ...

  5. Visual Studio进行Web性能测试- Part I

    Visual Studio进行Web性能测试- Part I 2012-08-29 08:01 by 知平软件, 5356 阅读, 9 评论, 收藏, 编辑 原文作者:Ambily.raj Visua ...

  6. Redis】Java中使用Jedis操作Redis(Maven导入包)、创建Redis连接池

    如果我们使用Java操作Redis, 需要确保已经安装了 redis 服务及 Java redis 驱动. Maven项目可以直接在pom.xml中加入jedis包驱动: <!-- https: ...

  7. springboot nginx 配置

    安装nginx参考本人另一篇博客:http://www.cnblogs.com/gmq-sh/p/5750833.html spring-boot需要启动nginx的,用于监听启动的端口.一.配置ng ...

  8. 时间序列异常检测算法S-H-ESD

    1. 基于统计的异常检测 Grubbs' Test Grubbs' Test为一种假设检验的方法,常被用来检验服从正太分布的单变量数据集(univariate data set)\(Y\) 中的单个异 ...

  9. win下查找端口占用进程并定位到具体程序

    很多时候,我们会在服务器上运行多个java程序,但是在任务管理器里看到的都是一样的图标,想要找到我们想要的那个进程咋办呢? 列出所有端口进程 C:\Users\desp>netstat -ano ...

  10. java幂等性的解决方案

    一.幂等性概念 在编程中.一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同.幂等函数,或幂等方法,是指可以使用相同参数重复执行,并能获得相同结果的函数.这些函数不会影响系统状态,也 ...