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 ...
随机推荐
- 编码规范(CSS)
code { font-family: "PT Mono", Menlo, "Courier New", monospace; padding: 2px 4px ...
- SICP 习题 (1.9) 解题总结
SICP 习题 1.9 开始针对“迭代计算过程”和“递归计算过程”,有关迭代计算过程和递归计算过程的内容在书中的1.2.1节有详细讨论,要完成习题1.9,必须完全吃透1.2.1节的内容,不然的话,即使 ...
- Why Hadoop2
自从Hadoop2出现之后,其迅速代替了Hadoop1的地位,并丰富了Hadoop的应用场景.假设如今有公司使用Hadoop的话,往往直接採用Hadoop2了. Hadoop2能被如此广泛的使用,肯定 ...
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问的解决方案
今天写了一个excel表的导入功能,结果在excel表中的内容导入到页面时报错:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT ...
- CSS减肥的工具–Firefox插件 CSS Usage
首先,我们需要安装Firefox(猛击此处下载),或者确定你已经安装的版本已经高于3.1; 第二步,安装前端开发人员最普及的开发工具 Firebug: 第三步,安装CSS Usage 0.3.4.1: ...
- Android Path
外置SDCard(TF卡) 1. SDCard的挂载路径(根据系统不同的ROM挂载的路径不同,以下列举几个是从旧系统到新系统的表现形式) /sdcard/external_sd /mnt/extSdC ...
- mvc分页生成静态页,mvc生成静态页
http://blog.csdn.net/xxj_jing/article/details/7899125 分页生成静态页 http://www.cnblogs.com/luanyilin/archi ...
- ckplayer,超酷网页播放器,用于集成在网站中的播放器
自己在工作中做了一个教学网站,点击左边课程,右边播放视频,经过源代码分析,用的就是这个播放器 网址:http://www.ckplayer.com/ 具体使用播放器网站上说的比较明白 div id=& ...
- Repeater控件的详细用法
中隔行(交替项)呈现一次.通过设置 AlternatingItemTemplate 元素的样式属性,可以为其指定不同的外观. FooterTemplate在所有数据绑定行呈现之后呈现一次的元素.典型的 ...
- 基于canvas图像处理的图片展示demo
图片展示网页往往色彩繁杂,当一个网页上有多张图片的时候用户的注意力就很不容易集中,而且会造成网站整个色调风格的不可把控. 能不能把所有的预览图变成灰度图片,等用户激活某张图片的时候再上色呢? 以前,唯 ...