leetcode982 Triples with Bitwise AND Equal To Zero
思路:
使用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的更多相关文章
- 【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 < ...
- [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 & ...
- 【LeetCode】982. Triples with Bitwise AND Equal To Zero 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode 982. Triples with Bitwise AND Equal To Zero
题目链接:https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero/ 题意,已知数组A,长度不超过1000,最大的数不超 ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- Weekly Contest 121
984. String Without AAA or BBB Given two integers A and B, return any string S such that: S has leng ...
- leetcode hard
# Title Solution Acceptance Difficulty Frequency 4 Median of Two Sorted Arrays 27.2% Hard ...
- 【Leetcode周赛】从contest-121开始。(一般是10个contest写一篇文章)
Contest 121 (题号981-984)(2019年1月27日) 链接:https://leetcode.com/contest/weekly-contest-121 总结:2019年2月22日 ...
- 【CF1174D】 Ehab and the Expected XOR Problem - 构造
题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...
随机推荐
- C++之STL迭代器
迭代器是一种检查容器内元素并遍历元素的数据类型.可以替代下标访问vector对象的元素. 每种容器类型都定义了自己的迭代器类型,如 vector: vector<int>::iterato ...
- ftp连接服务器失败||或者Xshell链接错误:Could notconnect to '192.168.18.128' (port 22): Connection failed
有时候刚装完虚拟机发现xshell连接失败,或者使用ftp连接失败.(博主用的是unbuntu,其他linux系统可能在命令上稍有差别,但方法是一样的. xshell连接失败: ftp连接失败: 首先 ...
- zabbix proxy安装及使用
首先我萌先理解下为什么要突然冒出zabbix proxy 它是一个代理,也就是agent与server的中间层,他会代替server收集agent的数据保存起来,然后推送给server,那么很明显,它 ...
- RTC驱动程序分析
drivers\rtc\rtc-s3c.c s3c_rtc_init platform_driver_register s3c_rtc_probe ...
- 计时器 vb
十分钟 我们寒假就是这么长!! vb 执行cmd : shell "cmd /c DOS命令" vb 取系统日期: Print Date; " ...
- getElementsByName()获取标签时的注意
var aDiv = document.getElementsByTagName('div');//获取的标签名注意你下面用的是哪一个div的标签名,例如 aDiv[0] 才可以: <!-- 注 ...
- wp8环境搭建
Windows Phone 8将采用与Windows 8相同的NT内核,这就意味着WP8将可能兼容Win8应用,开发者仅需很少改动就能让应用在两个平台上运行.由于内核变更,Windows Phone ...
- AspNetPager样式以及属性帮助文档
帮助文档地址:http://www.webdiyer.com/AspNetPagerDocs/index.html 应用样式:http://www.webdiyer.com/AspNetPagerDe ...
- git 系统中 post-receive 钩子不能正常执行 git pull 解决方法
有一个需求是本地git在push到远程 git repo 之后,在远程服务器上自动在/dir/foo下执行 git pull 的操作.想来是一个很简单的需求,不就是在远程的 foo.git 仓库中的 ...
- HTML5的LocalStorage实现记住密码
HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 session 的数据存储 localStorage ...