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,j∈S, 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 (1≤n≤100000), indicating the length of the sequence.
The second line contains n integers: a1 ,a2 ,...,an(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的更多相关文章
- 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,. ...
- XOR Clique(按位异或)
XOR Clique(按位异或): 传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4057 准备:异或:参加运算的两 ...
- ZOJ 4057 XOR Clique(位运算)
XOR Clique BaoBao has a sequence a1,a2,...,an. He would like to find a subset S of {1,2,...,n} s ...
- 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 ...
- The 2018 ACM-ICPC Asia Qingdao Regional Contest(青岛网络赛)
A Live Love 水 #include <algorithm> #include<cstdio> #include<cstring> using namesp ...
- 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 ...
- The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online(2018 青岛网络预选赛)
A题 A Live Love 原题链接:https://pintia.cn/problem-sets/1036903825309761536/problems/1041155943483625472 ...
- Atcoder Beginner Contest 121 D - XOR World(区间异或和)
题目链接:https://atcoder.jp/contests/abc121/tasks/abc121_d 题目很裸(Atcoder好像都比较裸 就给一个区间求异或和 n到1e12 肯定不能O(n) ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 xor (根号分治)
xor There is a tree with nn nodes. For each node, there is an integer value a_iai, (1 \le a_i \le ...
随机推荐
- JAVA自学笔记13
JAVA自学笔记13 1.StringBuffer类 1)线程安全的可变字符序列 线程安全(即同步) 2)StringBuffer与String的区别:一个可变一个不可变 3)构造方法: ①publi ...
- Hibernate(8)_单向n对n
1.n-n 的关联必须使用连接表 与1-n映射类似,必须为set集合元素添加 key 子元素,需要指定中间表 2.实体类 Category.java public class Category { p ...
- Oracle中连接与加号(+)的使用
1.左外连接(Left outer join/ left join) left join是以左表的记录为基础的,左表的记录将会全部表示出来,而右表只会显示符合搜索条件的记录.右表记录不足的地方均为NU ...
- 尚未备份数据库 "***" 的日志尾部。如果该日志包含您不希望丢失的工作,请使用 BACKUP LOG WITH NORECOVERY 备份该日志。
使用SQL Server 2005还原备份的数据库文件时出现的问题,如题. 前提:如果你有个数据库的.bak的备份文件. 右键点击 数据库任务-->还原-->数据库 1.还原的目标选择你要 ...
- python测试开发django-55.xadmin使用markdown文档编辑器(django-mdeditor)
前言 markdown是一个非常好的编辑器,用过的都说好,如果搭建一个博客平台的话,需要在后台做文章编辑,可以整合一个markdown的文本编辑器. github上关于django的markdown插 ...
- jqeury-地区三级联动
html+js <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www ...
- SpringBoot(十三):springboot2.0.2定时任务
使用定义任务: 第一步:启用定时任务第二步:配置定时器资源等第三步:定义定时任务并指定触发规则 1)启动类启用定时任务 在springboot入口类上添加注解@EnableScheduling即可. ...
- 我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=i5j7gwrxj9x5
我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=i5j7gwrxj9x5
- 系统管理员需知的 16 个 iptables 使用技巧
现代 Linux 内核带有一个叫 Netfilter[1] 的数据包过滤框架.Netfilter 提供了允许.丢弃以及修改等操作来控制进出系统的流量数据包.基于 Netfilter 框架的用户层命令行 ...
- [20170713] 无法访问SQL Server
背景: 朋友的环境第二天突然访问不了SQL Server,远程SQL Server用户无法登陆,但是本地SQL Server用户登录正常. 报错: 用户XX登录失败(MicroSoft SQL Ser ...