Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Everybody knows that opposites attract. That is the key principle of the "perfect matching" dating agency. The "perfect matching" matchmakers have classified each registered customer by his interests and assignedI-Th
Client numberTI(Cost-limit 10 ≤ costTILimit ≤ limit 10 ).
Of course, one number can be assigned to any number of MERs.
"Perfect matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite valuesT.
Each couple consists of exactly two clients. The customer can be stored in a couple an arbitrary number of times. Help the Agency and write the program that will find the sought number by the given sequenceT1, bytes,T2, middle..., middle ,...,TN.
For example, ifTOperator = Operator (1, operator-likelihood 1, Operator 1, operator-likelihood 1), then any two elementsTIAndTJForm
A couple ifIAndJHave
Different parity. Consequently, in this case the sought number equals 4.
Of course, a client can't form a couple with him/herself.
Input
The first line of the input data contains an integerN(1 digit ≤ DigitNLimit ≤ limit 105)
Which represents the number of registered clients of the "couple matching". The second line contains a sequence of IntegersT1, bytes,T2, middle..., middle ,...,TN(Cost-limit 10 ≤ costTILimit ≤ limit 10 ),TI-
Is the parameter ofI-Th customer that has been assigned to the customer by the result of the analysis of his interests.
Output
Print the number of couples of Customs with oppositeT. The opposite numberXIs
Number between-Limits-X(0 is opposite
To itself). Couples that only differ in the clients 'order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. please, do not use the % LLD specificator to read or write 64-bit integers in bytes ++. it is preferred to use Cin, cout streams or the % i64d specificator.
Sample test (s) Input
5-3 3 0 0 3
Output
3
Input
30 0 0
Output
3
Note
In the first sample the couples of opposite clients are: (1, 2), (1, 5) equal (3, 4 ).
In the second sample any couple of clients is opposite.
Description: This is used to calculate the sum of the logarithm numbers in a group and calculate 0. The simplest method is to use a two-layer loop. However, the number of N in this question is large and it is easy to time out. Read the question carefully and find that the Ti value is limited to [-10, 10]. Therefore, we should not record the value of each Ti, but calculate the number of each Ti value, then, we can calculate the number of occurrences of the opposite number and the sum of 0. However, because there are negative numbers in the question, the array subscript must not be negative. You can add 10 to the subscript. Edge input and edge statistics.
Number of times B [0]-10 appears
Number of times B [1]-9 appears
...
Number of times B [10] 0 appears
...
Number of occurrences of B [19] 9
Number of times B [20] 10 appears
Finally, calculate the value of B [I] * B [20-i]. Note that 0 in B [10] is paired by yourself, that is, CN ^ 2 in the permutation and combination.
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;int main(){int n,i,j;int a;double b[21];double sum;sum=0;scanf("%d",&n);for(i=0;i<21;i++){b[i]=0;}for(i=0;i<n;i++){scanf("%d",&a);b[a+10]++;}for(i=0;i<10;i++){sum+=b[i]*b[20-i];}sum+=b[10]*(b[10]-1)/2;printf("%.0lf\n",sum);return 0;}