#include<bits/stdc++.h>
using namespace std;
int s1[16000010];
int s2[16000010];
int main(){
int t,i,j,n,ans;
int a[4010],b[4010],c[4010],d[4010];
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
ans=0;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
s1[(i-1)*n+j]=a[i]+b[j];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
s2[(i-1)*n+j]=c[i]+d[j];
sort(s1+1,s1+n*n+1);
sort(s2+1,s2+n*n+1);
for(i=1;i<=n*n;i++)
ans+=upper_bound(s2+1,s2+n*n+1,-s1[i])-lower_bound(s2+1,s2+n*n+1,-s1[i]);
printf("%d\n",ans);
if(t)printf("\n");
}
return 0;
}
UVA 1152 4 Values whose Sum is 0 - ACM/ICPC SWERC 2005
最新推荐文章于 2020-12-22 11:48:11 发布