ZOJ - 3870 Team Formation (位运算)
来源:互联网 发布:node.js promise 编辑:程序博客网 时间:2024/05/25 21:35
Description
For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team fromN students of his university.
Edward knows the skill level of each student. He has found that if two students with skill levelA 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.
<h4< body="">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 containsN positive integers separated by spaces. The ith integer denotes the skill level ofith student. Every integer will not exceed 109.
<h4< body="">Output
For each case, print the answer in one line.
<h4< body="">Sample Input
231 2 351 2 3 4 5<h4< body="">
Sample Output
16
Hint
Source
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstring>#include<algorithm>const int MAXN = 100010;int a[MAXN], num[100];typedef long long LL;int geth(int x){int i;for(i = 0;;i++){if((1 << i) > x)break;}return i;}int main(){int T, N;scanf("%d", &T);while(T--){memset(num, 0, sizeof(num));scanf("%d", &N);for(int i = 0; i < N; i++){scanf("%d", a + i);num[geth(a[i])]++;}LL ans = 0;for(int i = 0; i < N; i++){if(a[i] > 0 && a[i] % 2 == 0)ans += num[0];for(int j = 1; (1 << (j - 1)) < a[i]; j++){if((a[i] ^ (1 << (j - 1))) > a[i])ans += num[j];}}printf("%lld\n", ans);}return 0;}
- ZOJ 3870 Team Formation(位运算)
- ZOJ 3870Team Formation(位运算)
- ZOJ - 3870 Team Formation (位运算)
- ZOJ-3870 Team Formation(位运算)
- ZOJ 3870 Team Formation 位运算
- zoj 3870 Team Formation 位运算
- ZOJ Team Formation 3870【位运算】
- zoj 3870 Team Formation(位运算,超时)
- ZOJ 题目3870 Team Formation(数学,位运算)
- zoj--3870--Team Formation(位运算好题)
- ZOJ-3870-Team Formation【位运算】【12th浙江省赛】
- Zoj 3870 Team Formation(异或运算)
- ZOJ 3870 Team Formation(异或运算)
- zoj 3870 Team Formation(异或运算)
- Zoj 3870 Team Formation(异或运算)
- Zoj 3870 Team Formation(异或运算)
- Zoj 3870 Team Formation(异或运算),zoj3870
- ZOJ 3870 Team Formation (异或运算)
- 用 Apache JMeter 测试 WebSphere 性能
- 2014年武汉的IT行情好像不太好(续):20个月过后,再看当时面试过的几个公司--武汉财富基石-崩盘,辣妈萌宝-创业失败,朋友公司转交他人管理
- POJ 1001--Exponentiation
- hdu 2647 Reward
- POJ 1177 Picture
- ZOJ - 3870 Team Formation (位运算)
- JAVA中extends 与implements区别
- 简单的传球游戏(矩阵快速幂) bnuoj49104
- leetcode-133. Clone Graph
- 算法(五)
- leetcode——120——Triangle
- leetcode 061 Rotate List
- 讲义四 包的理解
- 让requirejs不自动添加.js后缀