#include<cstdio>
#include<algorithm>
#include<unordered_map>
using namespace std;
#pragma warning(disable:4996)
int t, m[4000][4], n, a, s; unordered_map<int, int> H; pair<int, int> p; unordered_map<int, int>::iterator I;
int main() {
scanf("%d", &t); p.second = 1; //freopen("o.txt", "w", stdout);
for (int h = 0; h < t; ++h) {
scanf("%d", &n); a = 0; H.clear();
for (int i = 0; i < n; ++i)scanf("%d%d%d%d", &m[i][0], &m[i][1], &m[i][2], &m[i][3]);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
p.first = m[i][0] + m[j][1]; I = H.find(p.first);
if (I != H.end())++(*I).second;
else H.emplace(p);
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
s = -m[i][2] - m[j][3]; I = H.find(s);
if (I != H.end())a += (*I).second;
}
}
if (h > 0)putchar('\n');
printf("%d\n", a);
}
return 0;
}
UVA 1152 4 Values whose Sum is 0(unordered_map)
最新推荐文章于 2021-05-17 21:09:03 发布