Codeforces 609B The Best Gift 【水题】
来源:互联网 发布:有了源码怎么架设游戏 编辑:程序博客网 时间:2024/05/18 03:35
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个类别,现在你要买两本不属于同一类别的书,问有多少种方案。
暴力
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (1000+10)#define MAXM (100000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1#define PI acos(-1.0)using namespace std;map<int, int> fp;int main(){ int n, m; Ri(n); Ri(m); int op; fp.clear(); for(int i = 0; i < n; i++) Ri(op), fp[op]++; int ans = 0; for(int i = 1; i <= m; i++) for(int j = i+1; j <= m; j++) ans += fp[i] * fp[j]; Pi(ans); return 0;}
- 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【组合数学】
- 【CodeForces】609B - The Best Gift(水)
- CodeForces 609 B. The Best Gift(水~)
- CF 609B The Best Gift
- Educational Codeforces Round 3 B. The Best Gift
- Educational Codeforces Round 3 B.The Best Gift (数学)
- CodeForcess--609B--The Best Gift(模拟水题)
- Codeforces Educational Codeforces Round 3 B. The Best Gift(签到)
- CodeForces 609B The Best Giftgomg
- 【Educational Codeforces Round 3 B】【水题 基本容斥】The Best Gift n本书任选两个不能同一类型的方案数
- The best gift
- The Best Gift
- The Best Gift
- ios问题集
- iOS-计算两个日期的时间间隔
- MacOS10.11 brew无法使用解决办法
- frame和bounds的区别
- Xcode实时渲染——@IBDesignable
- Codeforces 609B The Best Gift 【水题】
- HIBERNATE 的乐观锁@VERSION和 MYSQL 的两个小问题
- Hibernate与Mysql 5.5创建表出错--table doesn't exist
- Ant+jmeter配置
- Android之.XML布局
- MmGetSystemRoutineAddress和MiFindExportedRoutineByName函数的实现代码
- stat函数讲解
- CSS3:伪对象选择器
- Zlib库的使用实现对zip文件的解压缩(二)