您的位置:首页 > 其它

UVA 11500

2016-06-06 20:42 344 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva