博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zoj 3870
阅读量:5102 次
发布时间:2019-06-13

本文共 2836 字,大约阅读时间需要 9 分钟。

B - Team Formation
Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu
Submit

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 AB, 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

231 2 351 2 3 4 5

Sample Output

16 题目描述 : 求一段序列中任意两个数,假设是a和b,(a^b)>max(a,b),这样的数对有多少个; 我们通过分析 a^b,发现假设a=110101,b
a是同样的情形),那么b的二进制长度小于a的二进制的长度, 发现b的最高位的1,如果a的相对应的位置为1,抑或之后的值一定会比a小,如果a的相对应的位置为0,那么抑或之后的值就会比a大; 这样我们就可以进行操作了, a=110101 有两种方式 1 : b=1 << (5,4,3,2,1,0) ,if((a & b)==0), 说明a相对应b二进制长度的那个位置上的数为0 2 : c=a >> (0,1,2,3,4,5),if((c & 1)==0),说明a的二进制某一对应位的那个位置上的数为0
#include 
#include
#include
#define M 100100using namespace std;int a[M];int input[M];int t;long long n;void init(){ memset(a,0,sizeof(a)); memset(input,0,sizeof(input));}int getnum(int data){ int cnt=0; while(data>=1) { data >>=1; cnt++; } return cnt;}int solve(){ int x=0,answer=0,s=0; for(int i=1;i<=n;i++) { x=getnum(input[i]); ++a[x]; } //for(int i=1;i<=3;i++) // printf("%d ",a[i]); for(int i=1;i<=n;i++) { x=getnum(input[i]); //printf("%d\n",x); for(int pos=0;pos<=x-1;pos++) { int p= input[i] >> pos ; if( (p & 1 ) ==0) answer+=a[pos+1]; // printf("%d %d %d\n",pos,answer,input[i]); } } return answer;}int main(){ int T; // while(scanf("%d",&T)) // printf("%d\n",1 & T ); scanf("%d",&t); while(t--) { init(); scanf("%d",&n); for(int i = 1 ; i <= n ; i ++) { scanf("%d",&input[i]); } printf("%d\n",solve()); } return 0;}

 

 

转载于:https://www.cnblogs.com/xianbin7/p/4472634.html

你可能感兴趣的文章
Spring学习笔记
查看>>
6个有用的MySQL语句
查看>>
我对前端MVC的理解
查看>>
Silverlight实用窍门系列:19.Silverlight调用webservice上传多个文件【附带源码实例】...
查看>>
2016.3.31考试心得
查看>>
mmap和MappedByteBuffer
查看>>
Linux的基本操作
查看>>
转-求解最大连续子数组的算法
查看>>
算法为啥子那么难【转】
查看>>
对数器的使用
查看>>
OracleOraDb11g_home1TNSListener服务启动后停止,某些服务在未由其他服务或程序使用时将自己主动停止...
查看>>
Redis用户添加、分页、登录、注册、加关注案例
查看>>
练习2
查看>>
【ASP.NET】演绎GridView基本操作事件
查看>>
ubuntu无法解析主机错误与解决的方法
查看>>
尚学堂Java面试题整理
查看>>
08-【jsp重点】
查看>>
小记:xml画一个爱心。
查看>>
MySQL表的四种分区类型
查看>>
7.26
查看>>