CodeForces 609 B. The Best Gift(水~)

来源:互联网 发布:跟单软件下载 编辑:程序博客网 时间:2024/05/18 03:59

Description
有n本书分属于m类,每本都不同,现要选取两本种类不同的书,问有多少种选择方案
Input
第一行为两个整数n和m分别表示书的数量和种类数,之后为n个整数ai表示这n本书的种类(2<=n<=2*10^5,2<=m<=10,1<=ai<=m)
Output
输出选择两本不同种类书的种类数
Sample Input
4 3
2 1 3 1
Sample Output
5
Solution
水题,统计每种书的数量,之后暴力枚举所选取两本书的种类累加方案数即可
Code

#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;#define maxn 11typedef long long ll;int n,m,a[maxn];int main(){    while(~scanf("%d%d",&n,&m))    {        memset(a,0,sizeof(a));        while(n--)        {            int temp;            scanf("%d",&temp);            a[temp]++;        }        ll ans=0;        for(int i=1;i<=m;i++)            for(int j=i+1;j<=m;j++)                ans+=1ll*a[i]*a[j];        printf("%I64d\n",ans);    }     return 0;}
0 0