UVA 11500

来源:互联网 发布:制作搞笑图片软件 编辑:程序博客网 时间:2024/05/17 04:39

Thinking: This problem involves the gambler's ruin theorem.

wiki link


We can consider EV1/D , EV2/D as coins in the original problem. And in the theorem, P1,P2 represent the probability that person one or two's becoming penniless.

But here in the uva problem, the answer should be the probability that some one wins, thus p2 formula should be used. 



AC code:

#include<iostream>#include<cmath>using namespace std;int main(){    int ev1,ev2,at,d;    while(scanf("%d%d%d%d",&ev1,&ev2,&at,&d))    {        if(ev1||ev2||at||d)        {            int ev1c = ceil(1.0*ev1/d);            int ev2c = ceil(1.0*ev2/d);            double p = 1.0*at/6;// p(vampire1 wins)            double q = 1-p;            double q_over_p = q/p;            if(at == 3)            {                printf("%.1lf\n", 100.0*(double)ev1c/(ev1c+ev2c));            }            else{                double p_v1_wins = 100*(1-pow(q_over_p,1.0*ev1c))/(1-pow(q_over_p,1.0*(ev1c+ev2c)));                printf("%.1lf\n",p_v1_wins);            }        }        else break;    }return 0;}

0 0
原创粉丝点击