POJ 2785 4 Values whose Sum is 0
程序员文章站
2022-06-17 19:48:28
...
有 4 个序列,从每个序列中选一个数,求有多少种可能使得 4个数的和为0
const int N=4e3+5;
int n,m,t;
int i,j,k;
int a[N],b[N],c[N],d[N];
int cd[N*N];
int main()
{
//IOS;
while(~sd(n)){
for(i=0;i<n;i++){
sdd(a[i],b[i]);
sdd(c[i],d[i]);
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cd[i*n+j]=c[i]+d[j];
}
}
sort(cd,cd+n*n);
ll ans=0;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
int cur=-(a[i]+b[j]);
ans+=upper_bound(cd,cd+n*n,cur)-lower_bound(cd,cd+n*n,cur);
}
}
pld(ans);
}
//PAUSE;
return 0;
}
下一篇: Leetcode - 最长回文子串
推荐阅读
-
4 Values whose Sum is 0 POJ - 2785
-
4 Values whose Sum is 0
-
POJ 2785 4 Values whose Sum is 0
-
POJ 2785 4 Values whose Sum is 0(hash)
-
第四十二题 UVA1152 和为0的4个值 4 Values whose Sum is 0
-
POJ-2785 4 Values whose Sum is 0(二分+双指针)
-
POJ2785 4 Values whose Sum is 0
-
4 Values whose Sum is 0 POJ - 2785
-
4 Values whose Sum is 0 (折半枚举)
-
POJ-3441:4 Values whose Sum is 0--多元素之和判定