map
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 #include <map> 5 using namespace std; 6 7 map<int, int> a, b; 8 map<pair<int , int>, int> c; 9 long long ans; 10 int n, x, y; 11
struck Node
{
int x, y;
friend bool operator < (Node a, Node b)
{
return a.x < b.x;
}
}
map(Node, int) hcw;
12 int main() 13 { 14 scanf("%d", &n); 15 for (int i = 1; i <= n; i++) 16 { 17 scanf("%d %d", &x, &y); 18 ans += a[x]++; 19 ans += b[y]++; 20 ans -= c[make_pair(x, y)]++; 21 } 22 printf("%I64d", ans); 23 24 }
map用法: 相当于一个大的数组 可以把哈希用数组做不到的做到 方便不用开结构体 一定是两个元素 但是后面可以是一个数组或者两个数组
make_pair是一个内置的函数 (结构体) 当x和y一起出现的时候 他就会返回一个值。
a.clear();(清空)
浙公网安备 33010602011771号