博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 3870 Team Formation 位运算 位异或用与运算做的
阅读量:6914 次
发布时间:2019-06-27

本文共 1947 字,大约阅读时间需要 6 分钟。

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{

AB}).

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 ithinteger denotes the skill level of ith student. Every integer will not exceed 109.

<h4< dd="">Output

For each case, print the answer in one line.

<h4< dd="">Sample Input

231 2 351 2 3 4 5

<h4< dd="">Sample Output

16 题目的意思是从给出的所有数中选两个,如果这两个的位异或之后的值大于两个的最大值,那么说明这两个数符合要求 然后求的是所有符合要求的可能数 我这里是用与运算写的 补充一下  9&8=8,10&9=8,17&8=0,7&8=0 大家看懂了把  够直观了
#include
#include
#include
#include
#include
#define ls (u<<1)#define rs (u<<1|1)#define maxn 100010#define ll long long#define INF 1e9using namespace std;#define max(a,b) (a)>(b)?(a):(b)#define min(a,b) (a)<(b)?(a):(b)int a[maxn];int b[35];int main(){ int T; scanf("%d",&T); while(T--){ memset(b,0,sizeof b); int n; scanf("%d",&n); for(int i=0;i
=0;j--){ if((1<
=0;j--){ if(a[i]&(1<
=0;j--){ if(!(a[i]&(1<

 

转载于:https://www.cnblogs.com/l609929321/p/7295960.html

你可能感兴趣的文章
苹果拥抱IBM背后:大数据推动手机行业洗牌
查看>>
无线广播可以毁灭物联网安全:信号干扰器及犯罪
查看>>
《并行计算的编程模型》一3.7.1 选择集合参与者
查看>>
百分点:利用大数据做智慧商业
查看>>
让你的软件永生的7个规则
查看>>
《中国人工智能学会通讯》——12.23 隐私保护
查看>>
物联网五大应用实例,一看便明了!!
查看>>
中国人工智能学会通讯——众包中的统计推断与激励机制 4 我们能否有更好的付钱方式...
查看>>
GitLab宣布支持Git大文件存储Git LFS
查看>>
联想王震宇:联想企业网盘3.5版本的功能亮点
查看>>
监控蓄电池 保障数据中心正常运营
查看>>
浅析自动化设备安装运维的发展方向
查看>>
揭秘最高5Gbps的以太网标准IEEE 802.3bz
查看>>
Fortinet新中文名诠释新安全体系
查看>>
滴滴大脑告诉你,每一次派单背后都经历了什么
查看>>
从TensorFlow到Theano:横向对比七大深度学习框架
查看>>
VR的春天还要等多久?
查看>>
从思科推出1000万美元奖学金计划,看国内安全教育何去何从?
查看>>
品《阿里巴巴大数据实践-大数据之路》一书(下)
查看>>
4G促进智慧城市总体发展
查看>>