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. Python 协程(gevent)

    协程,又叫微线程,协程是一种用户态的轻量级线程. 协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文和栈保存到其他地方,在切回来的时候,恢复先前保存的寄存器上下文和栈.因此: 协程能保留上 ...

  2. DirectX 开发环境配置

      想使用DirectX开发游戏,前提是要搭建DirectX的开发环境啦. 下面我们就一起学习下DirectX开发环境搭建 1. 首先是DirectX SDK安装, 下载地址是: http://www ...

  3. 解决数据库Operation not allowed when innodb_forced_recovery > 0

    解决数据库Operation not allowed when innodb_forced_recovery > 0 请修改my.cnf innodb_force_recovery = 1 修改 ...

  4. sql service重置自动增长字段数字的方法

    1.--SQL表重置自增长字段(不删除表的数据) DBCC CHECKIDENT('表名', RESEED, 起始数) 2.--删除表数据的同时,重置自动增长字段 truncate table 表名

  5. c#中的表达式

    // 把变量和字面值(在使用运算符时,将它们统称为操作数)与运算符组合起来 // 就可以创建表达式,表达式是计算的基本构件 // 操作数可以是数值也可以是变量 + ; ; int num3 = num ...

  6. ASP.NET三层架构的分析

    BLL   是业务逻辑层   Business   Logic   Layer DAL   是数据访问层   Data   Access   Layer ASP.NET的三层架构(DAL,BLL,UI ...

  7. Button简单实例1

    1.XML按钮定义 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" an ...

  8. 006 列表的三种删除方法 remove,pop,del

    先定义一个列表: number=[,'changhao','常浩',5.2] . remove(): number.remove('changhao')---括号内是要删除的单一值 . pop(): ...

  9. mysql升级后报Table 'mysql.servers' doesn't exist

    解决Table 'mysql.servers' doesn't exist 今天遇到一事,就是我在升级mysql数据库后进入数据建立一远程用户,结果报错了. mysql> flush privi ...

  10. Js 导出Excel IE ActiveX控件

    function ExportExcel() { var oXL = new ActiveXObject("Excel.Application"); //创建excel应用程序对象 ...