题目链接 http://vjudge.net/problem/UVA-10056
解题思路
求等比级数收敛于多少。
当公比小于1时,等比级数收敛,收敛于: a1/(1-q)
代码
#include<stdio.h> #include<math.h> double cal(double p, double q, int tot, int people) { if(p == 0) return 0; int lost = people - 1; double ans = 0, t = 1; double bi = pow(q, tot); for(int i=1; i<=lost; i++) t *= q; t *= p; ans = t / (1 - bi); return ans; } int main() { int test; scanf("%d", &test); while(test--) { int num, k; double g; scanf("%d%lf%d", &num, &g, &k); printf("%.4lf\n", cal(g, 1-g, num, k)); } return 0; }