题意
求 |xi−xj|+|yi−yj|=(xi−xj)2+(yi−yj)2−−−−−−−−−−−−−−−−−√ 的个数。
题解
显然,只有 xi==xj 或者 yi==yj 的时候才相等。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int, int> px, py;
map<pair<int, int>, int> ps;
int main()
{
int n, x, y;
cin >> n;
for(int i = 0; i < n; ++i){
scanf("%d %d", &x, &y);
px[x]++, py[y]++;
ps[make_pair(x, y)]++;
}
ll ans = 0;
for(auto &it: px){
int cnt = it.second;
ans += (ll)cnt * (cnt - 1) / 2;
}
for(auto &it: py){
int cnt = it.second;
ans += (ll)cnt * (cnt - 1) / 2;
}
ll samepair = 0;
for(auto &it: ps){
int cnt = it.second;
if(cnt > 1) samepair += (ll)cnt * (cnt - 1) / 2;
}
cout << ans - samepair << endl;
return 0;
}