###### uva 1152 - 4 Values whose Sum is 0

#include<cstdio>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int maxn=4005;
unordered_map<int,int>cnt;
int a[maxn],b[maxn],c[maxn],d[maxn];
int n;
void solve(){
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(cnt.count(-a[i]-b[j])){
ans+=cnt[-a[i]-b[j]];
}
}
}
printf("%d\n",ans);
}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T,kase=0;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
}
cnt.clear();
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(!cnt.count(c[i]+d[j])){
cnt[c[i]+d[j]]=0;
}
cnt[c[i]+d[j]]++;
}
}
if(kase++){
printf("\n");
}
solve();
}
return 0;
}

#### uva1152 4 Values whose Sum is 0（中途相遇法）

2016-01-17 14:26:57

#### [算法竞赛入门经典] UVA 1152 - 4 Values whose Sum is 0 | POJ 2785

2014-08-15 19:00:47

#### POJ2785：4 Values whose Sum is 0(二分)

2014-08-18 16:37:11

#### 北大ACM2785——4 Values whose Sum is 0~~双向搜索

2015-06-30 15:56:55

#### Uva - 1152 - 4 Values whose Sum is 0

2015-06-21 13:33:59

#### uva 1152 4 Values whose Sum is 0

2015-08-12 23:47:17

#### UVA 1152 4 Values whose Sum is 0

2015-08-31 09:30:47

#### UVA - 1152 4 Values whose Sum is 0

2015-10-22 10:57:06

#### 4 Values whose Sum is 0 UVA - 1152

2017-08-27 11:31:29

#### UVA 1152 4 Values whose Sum is 0

2017-09-15 14:37:45

## 不良信息举报

uva 1152 - 4 Values whose Sum is 0