Opposites Attract

发布时间:2017-3-25 12:00:18 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Opposites Attract",主要涉及到Opposites Attract方面的内容,对于Opposites Attract感兴趣的同学可以参考一下。

Description 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 ti ( - 10 ≤ ti ≤ 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 t1, t2, ..., tn. For example, if t = (1,  - 1, 1,  - 1), then any two elements ti and tj 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. Input 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 integerst1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-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 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. Sample Input 5 -3 3 0 0 33 0 0 0 Sample Output 33#include<stdio.h> #include<string.h> int main() { int i,n,x; __int64 count,a[30]; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); for(i=0;i<n;i++) { scanf("%d",&x); a[10+x]++; //此处技巧 } count=0; for(i=0;i<=9;i++) count += a[i]*a[20-i]; count += a[10]*(a[10]-1)/2; printf("%I64d\n",count); } return 0; }

上一篇:百度收录seo等方法总结
下一篇:开店攻略: 现代促销的七种促销策略

相关文章

关键词: Opposites Attract

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款