uva10056-概率是多少

Posted 啊嘞

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva10056-概率是多少相关的知识,希望对你有一定的参考价值。

题目链接 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;
}

 

以上是关于uva10056-概率是多少的主要内容,如果未能解决你的问题,请参考以下文章

UVA10056 What is the Probability概率

UVA 12034 Race

UVA10491 - Cows and Cars(概率)

[UVA - 12034] Race 题解

UVa 11468 Substring (AC自动机+概率DP)

UVA 11181 Probability|Given 数学 条件概率