#include<bits/stdc++.h> using namespace std; map<int,int> ans; int main() { ios::sync_with_stdio(false); int n,m; cin>>n>>m; for(int i=0;i<n;i++) { int a=0; for(int j=0;j<m;j++) { int x; cin>>x; a=a<<1; a+=x; } ans[a]++; } int sum =0; int maxn = (1<<m)-1; for(map<int,int>::iterator it=ans.begin(); it!=ans.end();it++) { int x = it->first; int num = x^maxn; sum += ans[num]*it->second; } cout<<sum/2; return 0; }
本文介绍了一种使用C++实现的位运算与映射(map)结合的优化算法,通过将输入数据转化为二进制位表示,并利用位运算进行快速匹配,最后通过映射记录并计算匹配结果,实现了高效的数据处理。该算法适用于处理大规模二进制数据的场景,如图像处理、信号处理等。
1万+

被折叠的 条评论
为什么被折叠?



