1 #include <bits/stdc++.h> 2 using namespace std; 3 int A[50010]; //50000个学生 4 int ans[2000000]; 5 int sum; 6 int main() { 7 int n, m; 8 cin >> n >> m; 9 for(int i = 0; i < n; i++) { 10 for(int j = 0; j < m; j++) { 11 int temp; 12 cin >> temp; 13 A[i] = (A[i] << 1) + temp;//2进制保存 14 } 15 ans[A[i]]++;//获得每个答案的人数 16 //cout << "A[i]:" << A[i] << " ans[A[i]]:" << ans[A[i]] << endl; 17 } 18 int max = (1 << m) - 1; 19 for(int i = 0; i < n; i++) { 20 int temp = A[i] ^ max;//按位取反 21 //cout << "temp:" << temp << " ans[temp]:" << ans[temp] << endl; 22 sum += ans[temp] ; 23 } 24 cout << sum / 2 << endl; 25 return 0; 26 }
原文:https://www.cnblogs.com/fx1998/p/12807116.html