【Educational Codeforces Round 3 B】【水题 基本容斥】The Best Gift n本书任选两个不能同一类型的方案数
来源:互联网 发布:seo入门博客 编辑:程序博客网 时间:2024/05/22 23:59
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=0x3f3f3f3f;int n,m,x;int a[12];LL C(LL x){return x*(x-1)/2;}int main(){while(~scanf("%d%d",&n,&m)){MS(a,0);for(int i=1;i<=n;++i){scanf("%d",&x);++a[x];}LL ans=C(n);for(int i=1;i<=m;++i)ans-=C(a[i]);printf("%lld\n",ans);}return 0;}/*【trick&&吐槽】注意不要爆int【题意】有n(2<=n<=2e5)本书,书有共计m(2<=m<=10)个类型。依次告诉你每本书的类型。我们想选出两本书,要求这两本书不能类型相同,问你有多少种选法。【类型】水题 简单容斥【分析】显然 C(tot,2)- ∑(i=1~m)C(typei,2)就是答案了。【时间复杂度&&优化】O(n)*/
0 0
- 【Educational Codeforces Round 3 B】【水题 基本容斥】The Best Gift n本书任选两个不能同一类型的方案数
- 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 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-B. The Best Gift【组合数学】
- 【CodeForces】609B - The Best Gift(水)
- CodeForces 609 B. The Best Gift(水~)
- Educational Codeforces Round 7-B. The Time(模拟)
- Educational Codeforces Round 22 B. The Golden Age(枚举)
- Educational Codeforces Round 23 B. Makes And The Product
- 用Imagick替代php的GD库
- 我在CSDN有自己的博客了,记住今天,记录自己的进步和成长
- 网上某位大神写的仿小米卸载动画eclipse版
- Revit二次开发(2):Hello World!
- OC_07_02 NSDate
- 【Educational Codeforces Round 3 B】【水题 基本容斥】The Best Gift n本书任选两个不能同一类型的方案数
- res/raw文件的存放和读取
- 155. Min Stack
- jQuery中this与$(this)的区别
- Revit二次开发(3):Revit动态模型更新(DMU: Dynamic Model Update)功能
- 快速搭建struts2+srping3+hibernate4框架
- ALV在保存带有小数的字段时候,在可编辑状态会自动少数
- SHU1919 Running Man,Bob(那罗延数)
- 元旦前随笔