程序员人生 网站导航

UVA - 10375 - Choose and divide (组合数)

栏目:php教程时间:2015-07-31 07:57:12


题目传送:UVA - 10375


思路:用double存答案,不过要注意是边乘边除,这样不会爆double,还有记得乘的时候要把int转换成double


AC代码:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <deque> #include <cctype> #define LL long long #define INF 0x7fffffff using namespace std; int main() { int p, q, r, s; while(scanf("%d %d %d %d", &p, &q, &r, &s) != EOF) { double ans = 1; int len = max(p, r); for(int i = 1; i <= len; i ++) { if(i <= q) { ans *= (p * 1.0 - q + i) / i; } if(i <= s) { ans *= i * 1.0 / (r - s + i); } } printf("%.5lf ", ans); } return 0; }



















------分隔线----------------------------
------分隔线----------------------------

最新技术推荐