Codeforces Round #672 (Div. 2) B. Rock and Lever题解(思维+位运算)
题目链接
题目大意
给你一个长为n(n<=1e5)的数组,让你求有多少对a[i]和a[j] (i!=j)满足a[i]&a[j]>a[i]^a[j]
题目思路
这些有关位运算的题目肯定是要把数字变成二进制的
在二进制中某一位的数只能是0或者1
0^0=0 0&0=0
0^1=1 0&1=0
1^0=1 1&0=0
1^1=0 1&1=0
这样你就会发现如果要&操做所获得的值更大,只有可能是最高位的1所处的位置相同
然后计算一下贡献即可
代码
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define fi first
#define se second
#define debug printf(" I am here\n");
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=2e5+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-10;
int n,a[maxn],num[40];
signed main(){
int _;scanf("%d",&_);
while(_--){
memset(num,0,sizeof(num));
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
int tot=0;
while(a[i]){
a[i]=a[i]/2;
tot++;
}
num[tot]++;
}
ll ans=0;
for(int i=0;i<=32;i++){
ans=(ans+1ll*num[i]*(num[i]-1)/2);
}
printf("%lld\n",ans);
}
return 0;
}
Codeforces Round #672 (Div. 2) B. Rock and Lever题解(思维+位运算)的更多相关文章
- Codeforces Round #672 (Div. 2 B. Rock and Lever (位运算)
题意:给你一组数,求有多少对\((i,j)\),使得\(a_{i}\)&\(a_{j}\ge a_{i}\ xor\ a_{j}\). 题解:对于任意两个数的二进制来说,他们的最高位要么相同要 ...
- Codeforces Round #721 (Div. 2)A. And Then There Were K(位运算,二进制) B1. Palindrome Game (easy version)(博弈论)
半个月没看cf 手生了很多(手动大哭) Problem - A - Codeforces 题意 给定数字n, 求出最大数字k, 使得 n & (n−1) & (n−2) & ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)
链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowerca ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】
A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #267 (Div. 2) B. Fedor and New Game【位运算/给你m+1个数让你判断所给数的二进制形式与第m+1个数不相同的位数是不是小于等于k,是的话就累计起来】
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
随机推荐
- F. Make It Connected 解析(思維、MST)
Codeforce 1095 F. Make It Connected 解析(思維.MST) 今天我們來看看CF1095F 題目連結 題目 給你\(n\)個點,每個點\(u\)還有一個值\(a[u]\ ...
- Kubernetes 搭建 ES 集群(存储使用 cephfs)
一.集群规划 使用 cephfs 实现分布式存储和数据持久化 ES 集群的 master 节点至少需要三个,防止脑裂. 由于 master 在配置过程中需要保证主机名固定和唯一,所以搭建 master ...
- 「MCOI-03」村国题解
第二篇题解! 可能是退役之前的最后一篇题解了 (好像总共都只写了两篇) 不说了,讲题: 题面 题意: 有T个数据 有一颗树(保证所有的的节点都是相连的),有n个节点,每个节点都有相应的权值与序号,现在 ...
- C++语言学习之STL 的组成
STL有三大核心部分:容器(Container).算法(Algorithms).迭代器(Iterator),容器适配器(container adaptor),函数对象(functor),除此之外还有S ...
- SQL删除语句DROP、TRUNCATE、 DELETE 的区别
主要介绍了SQL删除语句DROP.TRUNCATE. DELETE 的区别,帮助大家更好的理解和学习sql语句,感兴趣的朋友可以了解下 DROP: 1 DROP TABLE test; 删除表test ...
- C# 9.0 正式发布了(C# 9.0 on the record)
翻译自 Mads Torgersen 2020年11月10日的博文<C# 9.0 on the record> [1],Mads Torgersen 是微软 C# 语言的首席设计师,也是微 ...
- vscode搭建c++环境
第一步:下载 Vs Code 点击链接下载Vs Code 下载版本 并安装 https://code.visualstudio.com/ 点击 Download for Windwos 安装时 如 ...
- Java学习之路(一)——JDK的下载与安装
(一).JDK是Java开发工具包 下载网址:https://www.oracle.com/java/technologies/javase-downloads.html (二).安装 下载JDK以后 ...
- 激情的来源 Imagine how much you love it !
激情来自哪里?我想可能我找到了,精髓就在那个标题! 想象你有多么爱它!你就会爱上他,想象你有多么喜欢某一个东西,你很有可能就喜欢上他,着手去了解他,接触他. 如果带着这种想象状态的激情,工作和学习会有 ...
- 334. Increasing Triplet Subsequence(也可以使用dp动态规划)
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...