Educational Codeforces Round 3 B.The Best Gift (数学)
来源:互联网 发布:淘宝开店的类目 编辑:程序博客网 时间:2024/05/01 18:38
Educational Codeforces Round 3B:http://codeforces.com/contest/609/problem/B
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.
The books are given by indices of their genres. The genres are numbered from 1 to m.
The first line contains two positive integers n and m (2 ≤ n ≤ 2·105, 2 ≤ m ≤ 10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence a1, a2, ..., an, where ai (1 ≤ ai ≤ m) equals the genre of the i-th book.
It is guaranteed that for each genre there is at least one book of that genre.
Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109.
4 32 1 3 1
5
7 44 2 3 1 2 4 3
18
The answer to the first test sample equals 5 as Sasha can choose:
- the first and second books,
- the first and third books,
- the first and fourth books,
- the second and third books,
- the third and fourth books.
题目大意:共有n本书,m类不同的书,共有多少种两本不同类型的书的组合
直接统计每类书的个数计算即可
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int num[200005],n,m,i,ans;int main() { scanf("%d%d",&n,&m); memset(num,0,sizeof(num)); for(i=0;i<n;++i) { scanf("%d",num); ++num[num[0]];//统计每类书的个数 } ans=0; for(i=1;i<m;++i) { n-=num[i]; ans+=num[i]*n;//第i类数的每一本可以和后面的所有书组成一个组合 } printf("%d\n",ans); return 0;}
- Educational Codeforces Round 3 B.The Best Gift (数学)
- Educational Codeforces Round 3 B. The Best Gift
- Codeforces Educational Codeforces Round 3 B. The Best Gift(签到)
- ♥CodeForces 609B-B. The Best Gift【组合数学】
- 【Educational Codeforces Round 3 B】【水题 基本容斥】The Best Gift n本书任选两个不能同一类型的方案数
- 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
- Educational Codeforces Round 3 B
- Educational Codeforces Round 7--B. The Time
- Educational Codeforces Round 7 B. The Time
- 【CodeForces】609B - The Best Gift(水)
- CodeForces 609 B. The Best Gift(水~)
- Educational Codeforces Round 15 B. Powers of Two (数学)
- Educational Codeforces Round 7-B. The Time(模拟)
- Educational Codeforces Round 22 B. The Golden Age(枚举)
- hdu2669-Romantic
- 跳转后TabBar消失,返回后TabBar出现
- TextView属性详解
- web前端常用工具网址
- BST-----Validate Binary Search Tree
- Educational Codeforces Round 3 B.The Best Gift (数学)
- AWS 构建个人网站(1)
- Sencha Touch 自定义List的三种实现方案
- thrift在centos6.5下编译环境的安装
- VLC 视频播放资料 收集
- Spring集成Quartz定时任务框架介绍和Cron表达式详解
- __attribute__ 你知多少?
- 数据存储方式
- js简单实现图片切换效果