思路:

使用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. 「USACO13MAR」「LuoguP3080」 牛跑The Cow Run (区间dp

    题目描述 Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N ...

  2. 在浏览器上直接输入 http://www.bookEstore.com就可以访问工程问题

    关于在浏览器上直接输入 http://www.bookEstore.com就可以访问工程问题 1.在tomcat/conf/server.xml文件中配置一个虚拟主机 <Host name=&q ...

  3. bzoj 4711 小奇挖矿 ——“承诺”类树形dp

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4711 对“承诺”有了更深的了解. 向外和向内要区分,所以 f [ i ][ j ] 表示根向 ...

  4. Linux--top命令查看系统状态,所有值讲解

    Linux系统可以通过top命令查看系统的CPU.内存.运行时间.交换分区.执行的线程等信息.通过top命令可以有效的发现系统的缺陷出在哪里.是内存不够.CPU处理能力不够.IO读写过高. 一.top ...

  5. 3-3Java程序的结构

    这是类的定义 这是主方法的定义 类里面包含一个主方法,或者是主方法嵌套到我们的类里面 大括号要特别注意,通过大括号我们可以看到类和主方法的包含关系 class后面一定是跟的类的名字

  6. c# 字符串大小写转换

    //小转大 string lower = "converted from lowercase"; Console.WriteLine(lower.ToUpper()); //大转小 ...

  7. JsonCpp——json文件的解析

    定义: 官网: http://json.org/ 在线解析器:http://json.cn/ http://www.bejson.com/ JSON(JavaScript Object Notatio ...

  8. PhpStorm插件之Api Debugger

    安装插件 File->Setting->Pluugins   搜索  Api Debugger 如何使用 安装完插件后,RESTART IDE,在编辑器右侧 即可找到最新安装的 Api D ...

  9. git commit 提交不了 error: pathspec 'project'' did not match any file(s) known to git.

    1. 问题--使用git将代码提交到码云,使用到以下命令时: git commit -m 'init project' # 报错 error: pathspec 'project'' did not ...

  10. P4443 [COCI2017-2018#3] Dojave(线段树)

    传送门 设\(lim=2^n-1\),对于一个区间\([l,r]\)来说,如果\(sum\neq lim\)且能换出\(x\)并换进\(y\)来,使得\(sum\bigoplus a_x\bigopl ...