题干:

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 Tindicating 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 ithinteger 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

题目大意:

给n个数。任选两个数,如果异或大于他们两个数,那么方案数+1。问有多少种方案数。

解题报告:

可以发现,如果要让一个数增大,只要该数化为二进制后的出现0的位置跟1异或就会变大,同时需要满足另一个数的最高位为该数出现0位置的位数,如10可以跟1异或变为11 ,100可以跟10、11、1异或分别变为110,111,101,而101只能跟两位的进行异或,因为它的0出现的位置为第二位。

以上部分来自某题解、、

就说下实现吧:其实很简单排个序后从小往大扫,边统计答案边更新数组就行了。

这种题做多了。。见到都感觉是套路了、、

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int a[MAX];
int cnt[MAX];
int c[MAX];
int main()
{int t,n;cin>>t;while(t--){memset(cnt,0,sizeof(cnt));scanf("%d",&n);for(int i = 1; i<=n; i++) scanf("%d",a+i);sort(a+1,a+n+1);for(int x,cur,i = 1; i<=n; i++){x=a[i],cur = 0;while(x) {cnt[++cur]+=x%2;x/=2;}c[i]=cur;}ll ans=0;int all=n;for(int x,cur,i = 1; i<=n; i++) {ans += all-cnt[c[i]];all--;x=a[i],cur=0;while(x) {cnt[++cur] -= x%2;x/=2;}}printf("%lld\n",ans);} return 0;
}

【ZOJ - 3870】Team Formation(异或,思维)相关推荐

  1. zoj 3870 Team Formation

    题意: 给出n个数,问做多可以找到多少对数字A,B,使得A xor B > max(A,B). 思路: 感谢mzjj教本弱智. 对于一个数,只考虑小于它的数字. 假设对于一个数字x 110010 ...

  2. 费用流 ZOJ 3933 Team Formation

    题目链接 题意:两个队伍,有一些边相连,问最大组对数以及最多女生数量 分析:费用流模板题,设置两个超级源点和汇点,边的容量为1,费用为男生数量.建边不能重复建边否则会T.zkw费用流在稠密图跑得快,普 ...

  3. JACK——TeamsMaual6 Team Formation

    来源:http://aosgrp.com/ 6 Team Formation This chapter describes team formation. It includes a descript ...

  4. 2021牛客暑期多校训练营4 E-Tree Xor(异或+思维+区间交 or Trie树)

    E-Tree Xor 首先不考虑区间限制条件,我们给定其中一个点的权值后,那么其他点的权值也就确定.比如 val1=0\text{val}_1=0val1​=0,即可通过变得限制求出其他点valu\t ...

  5. “科林明伦杯”哈尔滨理工大学暑假训练赛 B吃雪糕 (异或思维题)(补题)

    B吃雪糕 点击跳转 题 题目描述 桃也野正在吃很大一块雪糕,雪糕从左到右分成了n个区域,每个区域都有自己的口味,每种口味可以用一个数ai来描述.桃也野不喜欢吃口味相似的雪糕,如果ai⊕aj<2^ ...

  6. 【ZOJ - 4032】Magic Points (思维,几何,构造)

    题干: 解题报告: 想到了,这样绕圈构造.但是这样有个问题,最后一个点如何构造. 刚开始想的是n=奇数  ,  就8 10 这样的连一条,n=偶数  就8 11 这样的连一条,随便构造一下就行,但是发 ...

  7. 【Codeforces gym 102388】SUFE ICPC Team Formation Test,签到题BDG

    B Stars /* 题意:求二维平面上(x1,y1),(x2,y2)连成的直线上有多少个整数点 思路:以(x1,y1)为原点建立新的坐标系,答案为gcd(|x2-x1|,|y2-y1|)+1 */ ...

  8. 【2017年第3期】Talent Network:一个基于设计思维的企业社交网络服务

    夏帆, 丁铖, 钱卫宁, 周傲英, Gopakumar Gopalakrishnan, Anjaneyulu Passala 华东师范大学 中图分类号:TP391     文献标识码:A doi:10 ...

  9. TYUT-A专题题解(一)

    TYUT-A专题题解(一) 01A Ad Hoc UVA353 LA5247 Pesky Palindromes[回文] - 海岛Blog - CSDN博客 UVA947 Master Mind He ...

最新文章

  1. Hadoop–Task 相关
  2. ubuntu14.04 nginx php编译安装,Ubuntu 14.04 编译安装 Nginx
  3. ubuntu vscode 配置opencv3.0_ubuntu下配置vscode的c++环境
  4. 0也显示曲线 mpchart_BenQ 明基专业摄影显示器SW270C开箱评测体验
  5. DataKeyNames
  6. bootstrap 表格不用tr td如何写_Pandas还能用来写爬虫?
  7. Android开发学习笔记:浅谈Content Provider
  8. 感想2-对于组件化的一些思考
  9. 提取pdb氨基酸序列
  10. 手写字体怎么转换?如何快速转换字体?
  11. 福建省漳州市谷歌卫星地图下载
  12. 苹果11怎么录屏_苹果11突然黑屏是怎么回事?
  13. FLV(ACC+H264)文件格式分析
  14. Java String 真的是不可变的吗
  15. 音乐music says
  16. 抖音测试的软件,抖音app测试版
  17. 用 nanodet 训练口罩检测模型,并在 jetson nano 下部署测试
  18. Cilium 1.11 发布,带来内核级服务网格、拓扑感知路由....
  19. windows下分析恶意代码工具列表
  20. 记一次jasper的PDF模板父子报表实现功能

热门文章

  1. 212. Word Search II:多个单词查找
  2. CodeVS 1300 文字排版 线性DP
  3. windows server 触屏_宜昌触屏万能蒸烤箱价格-华春新能源有限公司
  4. java io体系_java IO流的体系结构图
  5. mysql change index_MySQL · 引擎特性 · Innodb change buffer介绍
  6. java 数字信号_数字信号处理理论及C++和Java实现 数字信号处理理论算法与实现...
  7. mysql-8.0.12语法_mysql-8.0.12 (免安装版) 安装详解
  8. layui 鼠标移入变为小手_游戏技术上不去?看看外设选对没!鼠标篇
  9. linux2.6内核Makefile详解
  10. 内核编译(make)