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;
}
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;
}
相关文章推荐
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- 9.401 - Palindromes
- A.537 - Artificial Intelligence?