Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu

Submit
Status

Description

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.
AB > max{A, B}).

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

Hint

Source

The 12th Zhejiang Provincial Collegiate Programming Contest
神奇的位运算

#include<cstdio>
#include<cstring>
int a[100100];
int num[40];
void sum(int x)
{
int pos=31;
while(pos>=0)
{//1左移31位,&同为1时为1,其他为0
if(x&(1<<pos))//寻找最高的二进制位
{
num[pos]++;
return ;
}
pos--;
}
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum(a[i]);
}
long long ans=0;
for(int i=0;i<n;i++)
{
int pos=31;
while(pos)
{
if(a[i]&(1<<pos))
break;
pos--;
}
while(pos>=0)
{
if(!(a[i]&(1<<pos)))
ans+=num[pos];//num中存储的最高位为pos的数的个数
pos--;
}
}
printf("%lld\n",ans);
}
return 0;
}

zoj--3870--Team Formation(位运算好题)的更多相关文章

  1. ZOJ 3870 Team Formation 位运算 位异或用与运算做的

    For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-m ...

  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 3870——Team Formation——————【技巧,规律】

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

  4. ZOJ 3870 Team Formation 贪心二进制

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

  5. ZOJ - 3870 Team Formation(异或)

    题意:给定N个数,求这N个数中满足A ⊕ B > max{A, B})的AB有多少对.(A,B是N中的某两个数) 分析: 1.异或,首先想到转化为二进制. eg:110011(A)和 1(B)- ...

  6. 蓝桥杯---汉字取首字母(位运算 & 水题)

    确实题目虽然有点水,但是开始的时候好像还真的没有想到怎么提取出这个编号一不小心感觉可以可以用unsigned char 这种类型,直接转为16进制,但是之后发现虽然第一次在codeblock中还行,但 ...

  7. 【洛谷4424】[HNOI/AHOI2018] 寻宝游戏(位运算思维题)

    点此看题面 大致题意: 给你\(n\)个\(m\)位二进制数.每组询问给你一个\(m\)位二进制数,要求你从\(0\)开始,依次对于这\(n\)个数进行\(and\)或\(or\)操作,问有多少种方案 ...

  8. 【BZOJ4300】绝世好题(位运算水题)

    点此看题面 大致题意: 给你一个序列\(a\),让你求出最长的一个子序列\(b\)满足\(b_i\&b_{i-1}!=0\). 位运算+\(DP\) 考虑设\(f_i\)表示以第\(i\)个数 ...

  9. zzulioj--1832--贪吃的松鼠(位运算好题)

    1832: 贪吃的松鼠 Time Limit: 3 Sec  Memory Limit: 2 MB Submit: 43  Solved: 7 SubmitStatusWeb Board Descri ...

随机推荐

  1. 图解TCP/IP笔记(3)——IP协议

    目录 IP协议 IP寻址 IP地址组成 IP地址分类 广播地址 子网掩码 全局地址和私有地址 IP协议 跨越不同数据链路,实现两端节点之间的数据包传输 数据链路:只负责某一个区间之间的通信传输 IP协 ...

  2. [Windows Server 2008] Apache+PHP安全设置

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:Win2008 ...

  3. RadioButtonList的兩種實現方式

    一種是修改ItemTemplate,即ListBoxItem裏面的内容 <ListBox ItemsSource="{Binding}"> <ListBox.It ...

  4. CDR真实图片转水墨画效果制作教程

    CorelDRAW创造性滤镜组是最具有创造力的滤镜,使用里面的散开滤镜能够实现类似于水墨的表现手法,然后再结合图层的合并模式,让您的图片产生意想不到的视觉效果.本文将利用CorelDRAW软件中提供的 ...

  5. rsync 3.1.3

    rsyncd.conf 2018年1月28日 rsyncd配置(5) 2018年1月28日 姓名 rsyncd.conf配置rsync守护进程的方式在file for 概要 rsyncd.conf 描 ...

  6. ESX/ESXi 主机的某些存储阵列可能存在读取或写入性能问题 (1002598)

    Last Updated: 12/14/2018Categories: Troubleshooting  Details 免责声明:本文为 ESX/ESXi hosts might experienc ...

  7. @FunctionalInterface

    >> 函数式接口也称为SAM接口 Single Abstract Method interfaces 接口有且仅有一个抽象方法 允许定义静态方法 允许定义默认方法 允许java.lang. ...

  8. webpack-dev-middleware 与 webpack-hot-middlware

    dev-middleware:  live reload的实现: 思考一下我們要如何更新(live reload)呢? 當然是需要取得 webpack 編好的資料啊,於是就需要在從 request 到 ...

  9. css 字体单位之间的区分以及字体响应式实现

    问题场景: 在实现响应式布局的过程中,如何设置字体大小在不同的视窗尺寸以及不同的移动设备的可读性? 需要了解的有: 1.px,em,pt之间的换算关系 1em = 16px 1px  = 1/16 e ...

  10. uva 1587(Box UVA - 1587)

    题目大意是给定6个数对,每个数对代表一个面的长和宽,判断这6个面是否能构成一个长方体. 这种题一看很复杂,但是只要不想多了实际上这就是一个水题... 首先说明一下判断的思路: 1.长方体是有三个对面的 ...