Team Formation


Time Limit: 3 Seconds      Memory Limit: 131072 KB

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 ith integer denotes the skill level of ith student. Every integer will not exceed 109.

Output

For each case, print the answer in one line.

Sample Input

2
3
1 2 3
5
1 2 3 4 5

Sample Output

1
6

Author: LIN, Xi
Source: The 12th Zhejiang Provincial Collegiate Programming Contest

题解:

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

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<algorithm>
const int MAXN = ;
int a[MAXN], num[];
typedef long long LL;
int geth(int x){
int i;
for(i = ;;i++){
if(( << i) > x)break;
}
return i;
}
int main(){
int T, N;
scanf("%d", &T);
while(T--){
memset(num, , sizeof(num));
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%d", a + i);
num[geth(a[i])]++;
}
LL ans = ;
//for(int i = 0; i < 10; i++)printf("%d ", num[i]);puts("");
for(int i = ; i < N; i++){
if(a[i] > && a[i] % == )ans += num[];
for(int j = ; ( << (j - )) < a[i]; j++){
if((a[i] ^ ( << (j - ))) > a[i])ans += num[j];
// printf("i = %d %d %d\n", a[i], 1 << (j - 1), a[i] ^ (1 << (j - 1)));
}
//printf("%d ", ans);
}//puts("");
printf("%lld\n", ans);
}
return ;
}

Team Formation(思维)的更多相关文章

  1. ZOJ 3870:Team Formation(位运算&思维)

    Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...

  2. 位运算 ZOJ 3870 Team Formation

    题目传送门 /* 题意:找出符合 A^B > max (A, B) 的组数: 位运算:异或的性质,1^1=0, 1^0=1, 0^1=1, 0^0=0:与的性质:1^1=1, 1^0=0, 0^ ...

  3. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  4. 第十二届浙江省大学生程序设计大赛-Team Formation 分类: 比赛 2015-06-26 14:22 50人阅读 评论(0) 收藏

    Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...

  5. ZOJ3870 Team Formation

    /** Author: Oliver ProblemId: ZOJ3870 Team Formation */ /* 思路 1.异或运算,使用^会爆,想到二进制: 2.我们可以试着从前往后模拟一位一位 ...

  6. 2015 浙江省赛B Team Formation (技巧,动归)

    Team Formation For an upcoming programming contest, Edward, the headmaster of Marjar University, is ...

  7. Zoj 3870——Team Formation——————【技巧,规律】

    Team Formation Time Limit: 3 Seconds      Memory Limit: 131072 KB For an upcoming programming contes ...

  8. ZOJ 3870 Team Formation 贪心二进制

                                                    B - Team Formation Description For an upcoming progr ...

  9. 浙江省第十二届省赛 B - Team Formation

    Description For an upcoming programming contest, Edward, the headmaster of Marjar University, is for ...

随机推荐

  1. 用CSS/CSS3 实现 水平居中和垂直居中的完整攻略

    水平居中:行内元素解决方案 只需要把行内元素包裹在一个属性display为block的父层元素中,并且把父层元素添加如下属性即可:   .parent { text-align:center; } 水 ...

  2. 学习笔记DAY2

    Pycharm使用 1.添加模板 file => settings =>Editor=>file and code template => python script => ...

  3. .NET批量大数据插入性能分析及比较

    数据插入使用了以下几种方式 1. 逐条数据插入2. 拼接sql语句批量插入3. 拼接sql语句并使用Transaction4. 拼接sql语句并使用SqlTransaction5. 使用DataAda ...

  4. FlexSlider是一个非常出色的jQuery滑动切换插件

    FlexSlider是一个非常出色的jQuery滑动切换插件,它支持所有主流浏览器,并有淡入淡出效果.适合所有初级和高级网页设计师使用.不过很多人都只是使用默认的参数,今天来说说具体的参数来给大家看看 ...

  5. 未能加载文件或程序集“System.Web.Helpers, Version=2.0.0.0(转)

    在本地终于用上了ASP.NET MVC4自带的认证功能,但放到生产服务器上就出问题了:打开注册页面没问题,但一点下注册按钮就报错了: 未能加载文件或程序集“System.Web.Helpers, Ve ...

  6. 浏览器的Storage做缓存需要注意的地方

    使用浏览器的Storage来做缓存.如: window.sessionStorage.setItem("cache", $(data).stringify()) 需要注意以下几点: ...

  7. javascript延迟加载及异步(defer和async)

    一直以来写代码的时候的常用习惯就是吧所有的js文件直接加载在文档的head标签里面,在写js文件的时候有时候获取一些文件对象的时候为空对象,这是由于文档结构还没有加载完,但是js文件已经加载完.也就是 ...

  8. app->h5同步身份

    最近半年主要是进行手机端的开发,主要是H5平台和APP内嵌H5营销活动的支持,相对遇到的兼容性问题比较少些,只是iscroll性能,点透,手机浏览器缓存,手机性能提高. 今天总结下,工作项目中的app ...

  9. mac terminal的使用技巧

    1. 多tab支持    1)terminal y也是支持多tab的, Cmd+T可以打开一个新的tab    2) cmd + shift + { / } 可以在tab间切换   2. termia ...

  10. python笔记之中缀语法和管道实现

    python笔记之中缀语法和管道实现 你知道什么是中缀语法吗?你知道python中的中缀操作是什么吗?那你知道操作python也是可以像unix的管道符一样方便吗?那么,废话不说了,直接上代码. cl ...