题目传送: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\n", ans); } return 0; }
时间: 2024-10-13 14:42:35