第十二届浙江省大学生程序设计大赛-Team Formation 分类: 比赛 2015-06-26 14:22 50人阅读 评论(0) 收藏
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{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
#include <iostream>
#include <string>
#include <stdio.h>
#include<algorithm>
#include<string.h>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
const int MAX=100000+100;
int a[MAX],bit[35];
void solve(int x)
{
int b=31;
while(b>=0)
{
if(x&(1<<b))
{
bit[b]++;
return ;
}
b--;
}
}
int main()
{
int T,n,i,sum;
scanf("%d",&T);
while(T--)
{
sum=0;
memset(bit,0,sizeof(bit));
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
solve(a[i]);
}
for(i=0;i<n;i++)
{
int b=31;
while(b>=0)
{
if(a[i]&(1<<b))
{
break;
}
b--;
}
while(b>=0)
{
if(!(a[i]&(1<<b)))
{
sum+=bit[b];
}
b--;
}
}
printf("%d\n",sum);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
第十二届浙江省大学生程序设计大赛-Team Formation 分类: 比赛 2015-06-26 14:22 50人阅读 评论(0) 收藏的更多相关文章
- 第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏
Lunch Time Time Limit: 2 Seconds Memory Limit: 65536 KB The 999th Zhejiang Provincial Collegiate Pro ...
- 第十二届浙江省大学生程序设计大赛-Capture the Flag 分类: 比赛 2015-06-26 14:35 10人阅读 评论(0) 收藏
Capture the Flag Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In computer security, Ca ...
- 第十二届浙江省大学生程序设计大赛-Demacia of the Ancients 分类: 比赛 2015-06-26 14:39 30人阅读 评论(0) 收藏
Demacia of the Ancients Time Limit: 2 Seconds Memory Limit: 65536 KB There is a popular multiplayer ...
- 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏
May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...
- 第十二届浙江省大学生程序设计大赛-Beauty of Array 分类: 比赛 2015-06-26 14:27 12人阅读 评论(0) 收藏
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...
- 第十二届浙江省大学生程序设计大赛-Ace of Aces 分类: 比赛 2015-06-26 14:25 12人阅读 评论(0) 收藏
Ace of Aces Time Limit: 2 Seconds Memory Limit: 65536 KB There is a mysterious organization called T ...
- 团体程序设计天梯赛L1-020 帅到没朋友 2017-03-22 17:46 72人阅读 评论(0) 收藏
L1-020. 帅到没朋友 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为 ...
- 团体程序设计天梯赛L1-017 到底有多二 2017-03-22 17:31 155人阅读 评论(0) 收藏
L1-017. 到底有多二 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一个整数"犯二的程度"定义为该数 ...
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛--n a^o7 ! 分类: 比赛 2015-06-09 17:16 14人阅读 评论(0) 收藏
n a^o7 ! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 All brave and intelligent fighte ...
随机推荐
- org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map
mybatis 出现这个错误是 参数类型写错了.parameterType 写成了parameterMap
- NSDateFormatter
NSDate *now = [NSDate date]; NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; fmt.dateFormat = ...
- web 前端:连接mysql中文乱码问题的解决办法
当使用tomcat部署servlet连接时,总是出现各种原因的中文乱码问题.有的是因为mysql的默认字符集的问题,有的是客户端的字符配置问题. 现在对于这两种问题进行配置,来解决乱码. 服务器端(m ...
- C++之路进阶——poj2104(K-th Number)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 44537 Accepted: 14781 Ca ...
- C++之路进阶——codevs1285(宠物收养所)
1285 宠物收养所 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 最近,阿Q开了一间宠物收养所.收养所提供两种服 ...
- 如何彻底卸载MySQL
如何彻底卸载MySQL 下面给出完整的卸载MySQL 5.1的卸载方法: 1.控制面板里的增加删除程序内进行删除 2.删除MySQL文件夹下的my.ini文件,如果备份好,可以直接将文件夹全部删除 3 ...
- return 的用法 初探
#include<stdio.h> int imin(int ,int ); int main() { int evil1,evil2; ) //注意 第二个%d后面不能有空格,大概这就是 ...
- sql over开窗函数,
sql over开窗函数, 1.使用over子句与rows_number()以及聚合函数进行使用,可以进行编号以及各种操作.而且利用over子句的分组效率比group by子句的效率更高. 2.在订单 ...
- Fresco源码解析 - DataSource怎样存储数据
Fresco源码解析 - DataSource怎样存储数据 datasource是一个独立的 package,与FB导入的guava包都在同一个工程内 - fbcore. datasource的类关系 ...
- 夺命雷公狗---TP商城----TP之样式和特效以及图片引入---2
---恢复内容开始--- 刚才见到笑脸了,那么下一步就到我们的shop目录下创建一个Admin的目录了,然后将Home目录里面的东西全部都拉进去即可 然后我们回到shop\Home\View目录下创建 ...