Team Formation(思维)
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
Author: LIN, Xi
Source: The 12th Zhejiang Provincial Collegiate Programming Contest
题解:
N个球员,每个球员有一个水平值,现在要组队,每个队两个人,这个队的水平就是这两个人水平的异或,这个队能打好代表这个异或值大于人一个队员;问多少种组队方法;两个队不同即为任意一个队员不同;燕帅给提供的思路,就是记录每个人最高位出现的位置,对于每个人,只需找比这个人小的水平与其异或大于自己的个数和就好了;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<algorithm>
const int MAXN = ;
int a[MAXN], num[];
typedef long long LL;
int geth(int x){
int i;
for(i = ;;i++){
if(( << i) > x)break;
}
return i;
}
int main(){
int T, N;
scanf("%d", &T);
while(T--){
memset(num, , sizeof(num));
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%d", a + i);
num[geth(a[i])]++;
}
LL ans = ;
//for(int i = 0; i < 10; i++)printf("%d ", num[i]);puts("");
for(int i = ; i < N; i++){
if(a[i] > && a[i] % == )ans += num[];
for(int j = ; ( << (j - )) < a[i]; j++){
if((a[i] ^ ( << (j - ))) > a[i])ans += num[j];
// printf("i = %d %d %d\n", a[i], 1 << (j - 1), a[i] ^ (1 << (j - 1)));
}
//printf("%d ", ans);
}//puts("");
printf("%lld\n", ans);
}
return ;
}
Team Formation(思维)的更多相关文章
- ZOJ 3870:Team Formation(位运算&思维)
Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...
- 位运算 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^ ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- 第十二届浙江省大学生程序设计大赛-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 ...
- ZOJ3870 Team Formation
/** Author: Oliver ProblemId: ZOJ3870 Team Formation */ /* 思路 1.异或运算,使用^会爆,想到二进制: 2.我们可以试着从前往后模拟一位一位 ...
- 2015 浙江省赛B Team Formation (技巧,动归)
Team Formation For an upcoming programming contest, Edward, the headmaster of Marjar University, is ...
- Zoj 3870——Team Formation——————【技巧,规律】
Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contes ...
- ZOJ 3870 Team Formation 贪心二进制
B - Team Formation Description For an upcoming progr ...
- 浙江省第十二届省赛 B - Team Formation
Description For an upcoming programming contest, Edward, the headmaster of Marjar University, is for ...
随机推荐
- iOS 推送证书制作 (JAVA/PHP)
// aps_development.cer 转化成pem openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem ...
- Super Jumping! Jumping! Jumping!(dp)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Oracle 事务的開始与结束
事务是用来切割数据库活动的逻辑工作单元,事务即有起点,也有终点: 当下列事件之中的一个发生时,事务就開始了: 连接到数据库上,并运行了第一天 DML 语句: 当前一个事务结束后,又输入了另外一条 DM ...
- Android资源--颜色RGB值以及名称及样图
颜 色 RGB值 英文名 中文名 #FFB6C1 LightPink 浅粉红 #FFC0CB Pink 粉红 #DC143C Crimson 深红/猩红 #FFF0F5 L ...
- Qt Assistant 工作机制
Qt Assistant 是Qt 的助手,我们在看帮助的时候要用到的,它可以记住上一次你访问的位置. 1. 所以在你调用Qt Assistant为我们自己的程序写help的时候要记得修改qhcp配 ...
- WEB服务器5--IIS中ISAPI扩展、ISAPI筛选器
在IIS的文档中经常会提到两个术语:ISAPI扩展和ISAPI筛选器. ISAPI扩展 “ISAPI扩展(ISAPI Extension)”是一种可以添加到IIS中以增强Web服务器功能的程序,其载体 ...
- css2如何设置全屏背景图片
每次在做一个网站后台登陆页面的时候,当UI给我一张背景是不规律的背景图片,但是在设置为背景时,总会遇到屏幕大小的问题,导致背景图片有可能平铺.这样UI的效果达不到也会很难看. 本来我想用body{ba ...
- php + apache + mysql
http://archive.apache.org/dist/httpd/binaries/win32/ Apache msi 下载地址
- C# WebForm 使用NPOI 2 生成简单的word文档(.docx)
使用NPOI可以方便的实现服务端对Word.Excel的读写.要实现对Word的读写操作,需要引用NPOI.OOXML.dll,应用命名空间XWPF. 本文使用NPOI 2.0实现对Word的基本生成 ...
- cookie丢失、登陆自动退出问题解决
cookie保存在客户端或者内存中,不易丢失.但是在某些情况下会被忽略.在项目过程中遇到过跨域丢失的情况.在VS里面运行的程序,产生的cookie默认是没有domain值的,但是给它设定domain值 ...