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 ;
}


2015 浙江省赛B Team Formation (技巧,动归)的更多相关文章

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

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

  2. 2015 浙江省赛 H - May Day Holiday

    H - May Day Holiday As a university advocating self-learning and work-rest balance, Marjar Universit ...

  3. 2015 浙江省赛 Beauty of Array (思维题)

    Beauty of Array Edward has an array A with N integers. He defines the beauty of an array as the summ ...

  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. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(浙江省赛2015)

      Ace of Aces Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a mysterious organization c ...

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

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

  7. 位运算 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^ ...

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

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

  9. ZOJ3870 Team Formation

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

随机推荐

  1. Echarts的赋值,设置数据

    柱形图案例的赋值 相关文档参考:https://blog.csdn.net/yangsitong1314/article/details/76984616 <div class="ma ...

  2. ie7 动态改变select option时,宽度自动变短解决方法

    <html> <head> <title>JQuery</title> <meta http-equiv="pragma" c ...

  3. python3.7安装模块MySQLdb报错error: Microsoft Visual C++ 14.0 is required.

    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools&quo ...

  4. cf 814C 思维

    http://codeforces.com/contest/814/problem/C 给定一个字符串s,长度小于1500,进行q次询问q<=20w,每次询问输入一个m和一个字符c,求将最多m个 ...

  5. 51nod 1326 奇妙的spfa+dp

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1326 1326 遥远的旅途 题目来源: TopCoder 基准时间限制: ...

  6. IOS-SQLite3的封装

    IWStudent.h // // IWStudent.h // 02-SQLite的封装 // // Created by apple on 14-5-22. // Copyright (c) 20 ...

  7. python基础8之类的实例化过程剖析

    一.概述 之前我们说关于python中的类,都一脸懵逼,都想说,类这么牛逼到底是什么,什么才是类?下面我们就来讲讲,什么是类?它具有哪些特性. 二.类的语法 2.1 语法 class dog(obje ...

  8. 【spark】示例:求极值

    我们有这样的数据 1.建立SparkContext读取数据 (1)建立sc (2)通过sc.textFile()读取数据创建Rdd 2.过滤数据 通过filter(line => line.tr ...

  9. 猪齿鱼_01_环境搭建(二)_微服务支撑组件部署(Docker形式)

    一.前言 上一节,我们以源码形式部署好了猪齿鱼微服务组件,过程繁琐,且启动后占用了服务器大量的资源,对开发极其不友好.

  10. react privateRoute

    import React from 'react'; import PropTypes from 'prop-types'; import {Route,Redirect,withRouter} fr ...