CF131B.Opposites Attract
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 assigned to the i-th client number t__i ( - 10 ≤ t__i ≤ 10). Of course, one number can be assigned to any number of customers.
"Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of t. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence _t_1, _t_2, ..., t__n. For example, if t = (1, - 1, 1, - 1), then any two elements t__i and t__j form a couple if i and j have different parity. Consequently, in this case the sought number equals 4.
Of course, a client can't form a couple with him/herself.
众所周知,异性相吸。这正是“完美匹配”婚恋机构的核心原则。“完美匹配”机构的红娘们已根据每位注册客户所感兴趣的领域,对其进行了分类,并为第 i 位客户分配了一个数值 ti(其中 −10≤ti≤10)。当然,同一个数值可以被分配给任意数量的客户。
“完美匹配”希望宣传其服务,并公布“相反情侣”的数量,即满足 ti 与 tj 互为相反数的客户对 (i,j) 的数量。每对情侣恰好由两位客户组成;同一位客户可参与多对情侣(即允许重复使用)。请帮助该机构编写一个程序,根据给定序列 t1,t2,…,tn 计算出所求的对数。例如,若 t=(1, −1, 1, −1),则任意两个下标 i 与 j 满足奇偶性不同的元素 ti 和 tj 均构成一对相反情侣。因此,在此例中所求结果为 4。
当然,客户不能与自己配对。
输入格式
The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers _t_1, _t_2, ..., t__n ( - 10 ≤ t__i ≤ 10), t__i — is the parameter of the i-th customer that has been assigned to the customer by the result of the analysis of his interests.
输入数据的第一行包含一个整数 n(1≤n≤105),表示“情侣匹配”服务注册客户的数量。
第二行包含一个整数序列 t1,t2,…,tn(−10≤ti≤10),其中 ti 表示第 i 位客户根据其兴趣分析结果所得到的参数。
输出格式
Print the number of couples of customs with opposite t. The opposite number for x is number - 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 С++. It is preferred to use cin, cout streams or the %I64d specificator.
输出具有相反 t 值的海关对的数量。数值 x 的相反数为 - x(0 的相反数是其自身)。仅客户顺序不同的海关对被视为同一对。
注意:本题答案可能非常大,因此计算时必须使用 64 位整数类型。在 C++ 中,请勿使用 %lld 格式说明符读写 64 位整数;推荐使用 cin / cout 流,或使用 %I64d 格式说明符。
输入输出样例
输入#1
5 -3 3 0 0 3
输出#1
3
输入#2
3 0 0 0
输出#2
3
说明/提示
In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite.
在第一个样例中,相对的客户对为:(1,2)、(1,5) 和 (3,4)。
在第二个样例中,任意一对客户都是相对的。
输入解题思路,AI测评打分。不知道怎么写?