zoukankan      html  css  js  c++  java
  • The 2018 ACM-ICPC Asia Qingdao Regional Contest K XOR Clique

    K XOR Clique

    BaoBao has a sequence a1​​,a2​​,...,an​​. He would like to find a subset S of {1,2,...,n} such that i,jS, ai​​aj​​<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 (1n105​​), indicating the length of the sequence.

    The second line contains n integers: a1​​,a2​​,...,an​​ (1ai​​109​​), indicating the sequence.

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

    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 }


  • 相关阅读:
    无法访问计算机XXXX。错误是:库没有注册。
    Unix网卡重启命令
    教你如何进入有密码的 XP 系统
    巧妙恢复被破坏的Windows XP系统文件
    认识容灾备份 构筑一个避风港
    双机热备的实现模式 - 基于共享存储与纯软件方式
    玩大型游戏死机解决方法
    让windows xp开机跳过登陆界面
    在IE7中无法正常访问FTP的解决办法
    STL使用心得
  • 原文地址:https://www.cnblogs.com/fqfzs/p/9656928.html
Copyright © 2011-2022 走看看