2701: Party 排列组合问题
2010-11-01 13:09
351 查看
![](images/art.gif)
2701: Party
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
![]() | 1s | 8192K | 32 | 3 | Standard |
Input
Each test case begins with two integers N, M (N <= 1000, M <= 10000). Then M lines follows, each of them will contain two integers a and b, telling that a and b are friends. None of the friend relations will appear more than once in each test case. The inputs terminates when N = M = 0.Output
For each test case, print the number of shows to be performed in a single line.Sample Input
3 1 1 2 3 3 1 2 2 3 1 3 5 3 1 2 2 3 1 3 0 0
Sample Output
0 1 4
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int _link[10000];//_link[i]表示i认识多少人 int main() { int n,m; while(scanf("%d%d",&n,&m)==2&&n) { memset(_link,0,sizeof(_link)); while(m--) { int a,b;scanf("%d%d",&a,&b); _link[a]++,_link[b]++; } int res=0;//只有两个认识 for(int i=1;i<=n;i++) { res+=_link[i]*(n-_link[i]-1);//减去本身 } res>>=1;//减去相同情况 int cnt=n*(n-1)*(n-2)/6;//总情况 printf("%d/n",cnt-res); } return 0; }
相关文章推荐
- 小球的排列组合问题
- 求集合的组合和排列问题
- [转载]排列组合问题的通用算法
- 相同数不能相邻的排列问题 组合数学-容斥原理
- Oracle SQL排列组合之组合问题
- 字符串的排列组合问题
- 依旧排列组合问题
- 排列与组合问题
- poj 2249 排列组合问题
- iOS 借助排列组合求赛事投注的注数问题。
- C/C++ 排列组合问题(递归)
- 一个排列组合问题的解法
- n个元素中取m个元素的组合、排列问题
- 学习笔记-排列组合问题
- EularProject 24: 排列组合的序数问题
- 排列组合问题-母函数
- 排列组合之错排问题总结
- 排列组合问题
- 递归求解几类排列组合问题(五、生成全子集组合排列)
- noip 1995 灯的排列问题 排列组合 DFS