• XOR Clique


    https://pintia.cn/problem-sets/1036903825309761536/problems/1041156503909756928

    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
    

    作者: 浙江大学竞赛命题组

    单位: ACMICPC

    时间限制: 500 ms

    内存限制: 64 MB

    代码长度限制: 32 KB

    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    int main()
    {
    	int i,j;
    	for(i=0;i<=16;i++)
    	{
    		for(j=0;j<=100;j++)
    		{
    			if((i^j)<min(i,j))
    			printf("%d %d
    ",i,j);
    		
    		}
    	}
    	return 0;
    }

    可以看出规律,符合条件的在2^n与2^(n+1)之间,所以只要求在哪个阶段中的数最多即可。

    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    #define N 120
    int a[N];
    int main()
    {
    	int n,i,j,t,maxn,x;
    	scanf("%d",&t);
    	while(t--)
    	{    
    		maxn=0;
    		memset(a,0,sizeof(a));
    		scanf("%d",&n);
    		for(i=1;i<=n;i++)
    		{
    			scanf("%d",&x);
    			for(j=0;;j++)
    			{
    				if(x>=pow(2,j)&&x<pow(2,j+1))
    				{
    					a[j]++;	
    					maxn=max(a[j],maxn);
    					break;
    				}
    			}
    		}
    		printf("%d
    ",maxn);
    	}
    	return 0;
    }
  • 相关阅读:
    猫树
    单位根反演
    区间修改区间求和
    最远点 决策单调性
    圆方树
    912. 排序数组
    1309. 解码字母到整数映射
    28. 实现 strStr()
    31. 下一个排列
    22. 括号生成
  • 原文地址:https://www.cnblogs.com/zyq1758043090/p/10002988.html
Copyright © 2020-2023  润新知