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. TensorFlow-Gpu环境搭建——Win10+ Python+Anaconda+cuda

    参考:http://blog.csdn.net/sb19931201/article/details/53648615 https://segmentfault.com/a/1190000009803 ...

  2. 【译】x86程序员手册08 -2.6中断和异常

    2.6 Interrupts and Exceptions 中断和异常 The 80386 has two mechanisms for interrupting program execution: ...

  3. Escaping Closures 两点:本质是生命周期标示符

    1.block需要(拷贝)保存: 2.block引用的环境变量需要处理. 相当于oc中的copy block. Escaping Closures A closure is said to escap ...

  4. CentOS7阿里云服务器,python程序requests无法正常post网站(报502)

    问题描述: 使用jenkins构建接口自动化测试时,发现新增加的接口case不能访问通,会报502错误(本地可以跑通,在测试服就会502)解决的思路: 缩小调试范围(去掉jenkins db环境,将问 ...

  5. tab切换案例

    做个简单的tab切换效果,分别于jquery和js操作 (1)jQuery操作 先看下效果: <!DOCTYPE html> <html lang="en"> ...

  6. Android之手机振动和振铃

    一.振动的实现1.使用振动所需的权限 <uses-permission android:name="android.permission.VIBRATE" />2.相关 ...

  7. Luogu 2951 捉迷藏Hide and Seek

    P2951 [USACO09OPEN]捉迷藏Hide and Seek 题目描述 Bessie is playing hide and seek (a game in which a number o ...

  8. Spring Web MVC处理流程

    Spring Web MVC 处理流程: 1.浏览器向Spring发出请求,请求交给前端控制器 DispatcherServlet处理 2.控制器通过HandlerMapping找到相应的Contro ...

  9. 第十节:pandas之loc()、iloc()与ix()索引

  10. Tensorflow MNIST浅层神经网络的解释和答复

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51416540 看到之前的一篇博文:深入 ...