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 ...
随机推荐
- Luogu P2447 [SDOI2010]外星千足虫
题意 给定 \(n\) 个变量和 \(m\) 个异或方程,求最少需要多少个才能确定每个变量的解. \(\texttt{Data Range:}1\leq n\leq 10^3,1\leq m\leq ...
- .Net/.Net Core 的界面框架 NanUI 发布新版本啦!
发布前感悟 NanUI 自从上一次更新 NanUI 0.7 已经过去大半年,B站和头条的教学视频也只制作到了第二集. 有朋友悄悄问我是不是发生什么事故我删库跑路了所以那么长时间不更新项目不发布教程,当 ...
- Jumpserver简介,部署使用
Jumpserver简介 Jumpserver 是一款使用 Python, Django 开发的开源跳板机系统, 为亏联网企业提供了认证,授权,审计,自动化运维等功能,基于ssh协议来管理,客户端无需 ...
- 【Kata Daily 190918】Spacify(插空)
题目: Modify the spacify function so that it returns the given string with spaces insertedbetween each ...
- 17、ContentType组件
一 项目背景 路飞学成项目,有课程,学位课(不同的课程字段不一样),价格策略 问题: 1 如何设计表结构,来表示这种规则 2 为专题课,添加三个价格策略 3 查询所有价格策略,并且显示对应 ...
- tp3.2 php sdk上传七牛云
//获取上传token Vendor('sdk.autoload'); $accessKey='********'; $secretKey='*******'; $auth=new \Qiniu\Au ...
- 【Mycat】Mycat核心开发者带你轻松掌握Mycat路由转发!!
写在前面 熟悉Mycat的小伙伴都知道,Mycat一个很重要的功能就是路由转发,那么,这篇文章就带着大家一起来看看Mycat是如何进行路由转发的,好了,不多说了,我们直接进入主题. 环境准备 软件版本 ...
- C++ 设计模式--模板模式、策略模式、观察者模式
现代软件设计特征:需求频繁变化 设计模式的要点是"寻找变化点",在变化点应用设计模式,从而更好的应对需求变化. 1. Template Method 在软件构建结构中,往往他有整体 ...
- javascript函数式编程基础随笔
JavaScript 作为一种典型的多范式编程语言,这两年随着React\vue的火热,函数式编程的概念也开始流行起来,lodashJS.folktale等多种开源库都使用了函数式的特性. 一.认识函 ...
- 使用KepServerEx进行数据模拟
KepServerEx是一款在工业控制中比较常见的数据采集服务软件之一,提供了多种类型的驱动,具有比较广泛的适用性.很多厂商和个人都会选择用它来做OPCServer.在项目的实施或测试过程中,我们有时 ...