思路:

使用unordered_map暴力枚举。

实现:

 #include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
int countTriplets(vector<int>& A)
{
unordered_map<int, int> mp;
int n = A.size();
for (int i = ; i < n; i++)
{
for (int j = ; j < n; j++)
{
int tmp = A[i] & A[j];
if (!mp.count(tmp)) mp[tmp] = ;
mp[tmp]++;
}
}
int ans = ;
for (int i = ; i < n; i++)
{
for (auto it: mp)
if ((A[i] & it.first) == ) ans += it.second; }
return ans;
}
};
int main()
{
int a[] = {, , };
vector<int> v(begin(a), end(a));
cout << Solution().countTriplets(v) << endl;
return ;
}

leetcode982 Triples with Bitwise AND Equal To Zero的更多相关文章

  1. 【leetcode】982. Triples with Bitwise AND Equal To Zero

    题目如下: Given an array of integers A, find the number of triples of indices (i, j, k) such that: 0 < ...

  2. [Swift]LeetCode982. 按位与为零的三元组 | Triples with Bitwise AND Equal To Zero

    Given an array of integers A, find the number of triples of indices (i, j, k) such that: 0 <= i & ...

  3. 【LeetCode】982. Triples with Bitwise AND Equal To Zero 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  4. LeetCode 982. Triples with Bitwise AND Equal To Zero

    题目链接:https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero/ 题意,已知数组A,长度不超过1000,最大的数不超 ...

  5. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

  6. Weekly Contest 121

    984. String Without AAA or BBB Given two integers A and B, return any string S such that: S has leng ...

  7. leetcode hard

    # Title Solution Acceptance Difficulty Frequency     4 Median of Two Sorted Arrays       27.2% Hard ...

  8. 【Leetcode周赛】从contest-121开始。(一般是10个contest写一篇文章)

    Contest 121 (题号981-984)(2019年1月27日) 链接:https://leetcode.com/contest/weekly-contest-121 总结:2019年2月22日 ...

  9. 【CF1174D】 Ehab and the Expected XOR Problem - 构造

    题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...

随机推荐

  1. shell---rpm

    [root@master src]# rpm -qpl epel-release-latest-6.noarch.rpm         ##查询该rpm包安装了什么warning: epel-rel ...

  2. UNP总结 Chapter 11 名字与地址转换

    本章讲述在名字和数值地址间进行转换的函数:gethostbyname和gethostbyaddr在主机名字与IP地址间进行转换,getservbyname和getservbyport在服务器名字和端口 ...

  3. 编写 DockerFile

    编写 DockerFile 本节内容简介 在前面的实验中我们多次用到的 Dockerfile,在本实验里我们将通过完成一个实例来学习Dockerfile的编写. 本节中,我们需要依次完成下面几项任务: ...

  4. C# ActiveX 中static变量缓存的问题

    最近在忙活一个绘图程序,按照要求需要以ActiveX的方式发布在网站中,这个绘图程序的大概功能就是从数据库获取数据,成图.发布后用户反映,数据变化后,图形没有发生变化,好像有缓存,如果把浏览器全部关闭 ...

  5. Outlook 开发2

    转自:http://www.cnblogs.com/madebychina/archive/2011/09/20/madebychina_2.html C#使用如下代码调用Outlook2003发送邮 ...

  6. Ubuntu 安装杀毒软件防火墙

    1.打开终端 2.输入sudo apt-get install clamtk 3.按照提示安装 4.安装完成后,输入clamtk 即可. 卸载方法: 1.打开终端 2.输入sudo apt-get a ...

  7. 2 手写Java LinkedList核心源码

    上一章我们手写了ArrayList的核心源码,ArrayList底层是用了一个数组来保存数据,数组保存数据的优点就是查找效率高,但是删除效率特别低,最坏的情况下需要移动所有的元素.在查找需求比较重要的 ...

  8. 洛谷 - P1891 - 疯狂LCM - 线性筛

    另一道数据范围不一样的题:https://www.cnblogs.com/Yinku/p/10987912.html $F(n)=\sum\limits_{i=1}^{n} lcm(i,n) $ $\ ...

  9. 手把手教你使用ueditor

    ueditor的强大功能就不再一一叙述了,我们的目的就是通过使用php与html实现下面的效果 话不多说,上干货 前言:文件都是基于tp5的 1.引入富文本编辑器 将 ueditor 下的文件引入 1 ...

  10. bzoj 4873: [Shoi2017]寿司餐厅【最大权闭合子图】

    有正负收益,考虑最小割 因为有依赖关系,所以考虑最大权闭合子图 首先对每个d[i][j]建个点,正权连(s,id[i][j],d[i][j])并加到ans上,负权连(id[i][j],t,-d[i][ ...