URI ONLINE JUDGE SOLUTION 1289 - Online Judge

Latest

This is an Online Judge Solution Base Site. We can discuss & Solve any contest solution in Programming.

Friday, April 10, 2020

URI ONLINE JUDGE SOLUTION 1289

Problem Number: 1289
Problem Name: What is the Probability?
Author’s Name: By Shahriar Manzoor Bangladesh
Timelimit: 1
Problem Category: AD-HOC
Problem Source: https://www.urionlinejudge.com.br/judge/en/problems/view/1289

Solution:

#include <cstdio>

using namespace std;

#define sc1(a) scanf("%d", &a)
#define sc3(a,b,c) scanf("%d %lf %d", &a, &b, &c)
#define fr(i,a,n) for(int i = (a); i < (n); i++)

double p, pn, pi, s, r;
double exp(double p, int k);

int main(int argc, char const *argv[])
{
    int s, n, i;
    sc1(s);

    while(s--)
    {
        sc3(n,p,i);
        pn = exp(1 - p, n), pi = exp(1 - p, i - 1), r = pi;

        fr(j,0,10000)
        {
            pi *= pn;
            r += pi;
        }

        printf("%.4lfn", r * p);
    }

    return 0;
}

double exp(double p, int k)
{
    r = 1;
    fr(i,0,k)
        r *= p;

    return r;
}

No comments:

Post a Comment

Thanks..