poj1942求组合数
来源:互联网 发布:算法统宗校释 编辑:程序博客网 时间:2024/04/30 03:05
就是一求组合数的问题。
#include <iostream>#include <algorithm>using namespace std;#define ULL unsigned long long intint main(){ ULL a, b; while (cin >> a >> b && (a || b)) { if (b > a) swap(a, b); ULL s = 1, i, j; for (i = a + 1, j = 1; i <= a + b; i++, j++) { s = s * i / j; cout<<i<<" "<<j<<" "<<s<<endl; } cout << s << endl; }}
或者
/*强制类型转换输出*///Memory Time //220K 0MS #include<iostream>#include<math.h>using namespace std;/*Compute (n+m)C min{n,m}*/unsigned comp(unsigned n,unsigned m){unsigned a=m+n;unsigned b=(m<n?m:n);double cnm=1.0;while(b>0)cnm*=(double)(a--)/(double)(b--); cnm+=0.5; //double转unsigned会强制截断小数,必须先四舍五入return (unsigned)cnm;}int main(void){unsigned m,n;while(true){cin>>m>>n;if(!m && !n)//承认这题的猥琐吧!竟然有其中一边为0的矩阵,一定要&&,用||会WAbreak;cout<<comp(n,m)<<endl;}return 0;}
0 0
- poj1942求组合数
- poj1942线性复杂度求组合数
- poj1942 组合数
- poj1942 Paths on a Grid(组合数)
- poj1942-组合数学
- 1poj1942(组合数学)
- poj1942组合数学
- C++求组合数
- 求组合数
- 求组合数算法
- C++求组合数
- 求组合数
- C++求组合数
- 求组合数
- 求组合数
- 求组合数
- 求组合数!!!
- 求字符串组合数
- Android性能优化策略
- android 游戏 实战打飞机游戏 BOSS的设计 以及胜利失败页面(6结束)
- [从头学数学] 第231节 不定积分
- java数组和集合复习
- BitmapFactory.decodeStream。报错:SkImageDecoder::Factory returned null 原因及解决方法
- poj1942求组合数
- iOS 自定义分区头加上图片 以及导航控制器 颜色随滑动改变
- HDU - 4006 The kth great number (set&数据结构)
- SpringMVC 获得应用的绝对路径
- 如何使用libcurl实现HTTP的GET方法获取文件长度
- json解析
- Android自定义控件+popuwindow下拉菜单的实现仿58下拉菜单
- ANR traces分析 系统一直出现 waiting for ...日志
- CentOs7 开启网络连接