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
- 【CodeForces】609B - The Best Gift(水)
- CodeForces 609 B. The Best Gift(水~)
- Codeforces 609B The Best Gift 【水题】
- CodeForces 609B The Best Gift
- CodeForces 609B.The Best Gift
- CodeForces 609B The Best Gift
- CodeForces 609B The Best Gift
- ♥CodeForces 609B-B. The Best Gift【组合数学】
- CodeForcess--609B--The Best Gift(模拟水题)
- CF 609B The Best Gift
- Codeforces Educational Codeforces Round 3 B. The Best Gift(签到)
- Educational Codeforces Round 3 B. The Best Gift
- Educational Codeforces Round 3 B.The Best Gift (数学)
- CodeForces 609B The Best Giftgomg
- The best gift
- The Best Gift
- The Best Gift
- codeforces_609B. The Best Gift
- R语言学习:数据结构5-因子
- hdu1083二分图匹配
- Hibenate错误汇总:java.lang.NoClassDefFoundError:
- thinking in java 21_03
- bzoj2241 打地鼠 暴力&&二维差分
- CodeForces 609 B. The Best Gift(水~)
- GCD详解
- centos6修改YUM源方法
- binary-search-tree-iterator
- Android ListView 的基本用法
- R语言学习:数据结构6-缺失值
- 编写用户侧定时器
- 【quickSort】
- linux学习之c注释