Test instructions
Four sets, which require a number to be selected in each set, four numbers added to 0, and four numbers are added to zero several times.
Analysis:
First put the a+b and the sum in the array, and then find out-(c+b) the number of occurrences. Num:num=upper_bound (a,a+n,k)-lower_bound (a,a+n,k) of the number k in ordered array a of length n;
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm
using namespace std;
const int maxn=4005;
int t,n;
Int A[MAXN],B[MAXN],C[MAXN],D[MAXN],SUM[MAXN*MAXN];
Int main ()
{
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
int i,j;
for (i=0;i<n;i++)
scanf ("%d%d%d%d", &a[i],&b[i],&c[i],&d[i]);
int c=0;
for (i=0;i<n;i++)
for (j=0;j<n;j++)
Sum[c++]=a[i]+b[j];
Sort (sum,sum+c);
Long Long ans=0;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
Ans+=u Pper_bound (Sum,sum+c,-c[i]-d[j])-lower_bound (Sum,sum+c,-c[i]-d[j]);
}
}
printf ("%lld\n", ans);
if (T)
printf ("\ n");
}
}
UVA 1152 4 Values whose Sum is 0