Uva 11500 Solution

 Vampires Problem Solution By Gambler's Ruin Problem

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double Ev1, Ev2, At, D;

    while(cin >> Ev1 >> Ev2 >> At >> D)
    {
        if(Ev1 == 0 && Ev2 == 0 && At == 0 && D == 0)
            break;

        Ev1 = ceil(Ev1 / D);
        Ev2 = ceil(Ev2 / D);

        double p = At/6.0;
        double q = 1.0 - p;

        cout << showpoint;
        cout << fixed;
        cout << setprecision(1);

        if(p == q)
        {
            double ans = Ev1 / (Ev1 + Ev2);

            cout << ans * 100 << "\n";

            continue;
        }

        double r = q / p;

        double ans = (1 - pow(r, Ev1)) / (1 - pow(r, Ev1 + Ev2));

        cout << ans * 100 << "\n";
    }

    return 0;
}
 

Comments