Team Formation

For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team from N students of his university.

Edward knows the skill level of each student. He has found that if two students with skill level A and B form a team, the skill level of the team will be A ⊕ B, where ⊕ means bitwise exclusive or. A team will play well if and only if the skill level of the team is greater than the skill level of each team member (i.e. A ⊕ B > max{AB}).

Edward wants to form a team that will play well in the contest. Please tell him the possible number of such teams. Two teams are considered different if there is at least one different team member.

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 (2 <= N <= 100000), which indicates the number of student. The next line contains N positive integers separated by spaces. The ithinteger denotes the skill level of ith student. Every integer will not exceed 109.

<h4< dd="">Output

For each case, print the answer in one line.

<h4< dd="">Sample Input

2
3
1 2 3
5
1 2 3 4 5

<h4< dd="">Sample Output

1
6 N个球员,每个球员有一个水平值,现在要组队,每个队两个人,这个队的水平就是这两个人水平的异或,这个队能打好代表这个异或值大于人一个队员;
问多少种组队方法;两个队不同即为任意一个队员不同;
燕帅给提供的思路,就是记录每个人最高位出现的位置,对于每个人,只需找比这个人小的水平与其异或大于自己的个数和就好了; 位的问题,一半考虑排序从高位到低位

#include <iostream>
#include<cstring>
#include <string>
#include <algorithm>
using namespace std;
long long a[];
long long b[];
int main()
{
int t;
cin>>t;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
while(t--)
{
int n;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
sort(a+,a++n);//从小到大排,就只要考虑第一位
long long sum=;
for(int i=;i<=n;i++)
{
int x=a[i];
int ans=;
while(x)
{
ans++;
if(x%==) sum+=b[ans];//如果该位上是0,看前面有多少个1
x=x/;//向前进一位
}
b[ans]++;//这一位+1,比如1010,在b【4】++;
}
printf("%lld\n",sum);
}
return ;
}


最新文章

  1. 安装redis和php的redis扩展
  2. 版本python2和版本3.X的一个区别之一
  3. 史上最全的css hack(ie6-9,firefox,chrome,opera,safari) (zz)
  4. 圆形imageview
  5. RC4 加密算法asp版
  6. UVA 12219 Common Subexpression Elimination
  7. 天气渐热,来片雪花降降温——Android自定义SurfaceView实现雪花效果
  8. 微信小程序--图片相关问题合辑
  9. springBoot系列教程05:fastjson的集成、配置及使用
  10. Java基础系列--Executor框架(一)
  11. HBase 运维分析
  12. JS 面向对象 ~ 继承的7种方式
  13. js优化总结
  14. 【转】TCP和SOCKET关系
  15. map_server地图服务器
  16. Centos7安装jdk1.8并查找jdk安装目录
  17. JAVA开发微信支付-公众号支付/微信浏览器支付(JSAPI)
  18. [java实现]常见算法之字符串操作
  19. javaScript 中的一些日常用法总结
  20. JMeter学习笔记(六) 文件下载接口测试

热门文章

  1. Element UI 框架搭建
  2. NSNumber 与NSValue
  3. 实际工作中遇到关于Struts2线程安全的问题解决
  4. 六 web爬虫讲解2—urllib库爬虫—基础使用—超时设置—自动模拟http请求
  5. 51nod 1486
  6. Prism5.0新内容(纯汉语版)
  7. SpringBoot_09_使用jar包中配置的Bean(starter配置)
  8. UI-定时器与动画使用总结
  9. Week2《Java程序设计》第二周学习总结
  10. AngularJs 中的transclude的理解