UVA 11500 - Vampires

這是賭徒破產理論, 想了好久, 最後還是看別人教學了.
這大概就是數學問題的特點 - 如果你根本不知道相關理論, 問題是很難解的. (即使是數學家也要花不少時間才想出他的理論呢). 但如果你知道公式, 直接帶入公式就 AC 了.

當嬴的概率是 0.5 時

p1 when a is 3
p2 when a is 3

當嬴的概率不是 0.5 時

p1 when a != 3
p2 when a != 3

不過wiki的公式是玩家破產的概率. 而我們要的是嬴的概率, 也就是對方破產的概率. 
所以我們是用 P2 的公式. wiki 中的介紹還滿容易明白的, 可以仔細看一下.

wiki 連結

uva11500.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <cstdio>
#include <cmath>

int main () {
int ev1, ev2, at, d;

while (scanf("%d%d%d%d", &ev1, &ev2, &at, &d) != EOF && ev1) {
int ev1c = ceil( (double)ev1/d );
int ev2c = ceil( (double)ev2/d );
double winchance = at/6.0;
double qp = (1 - winchance)/winchance;

if(at == 3)
printf("%.1lf\n", 100 * (double)ev1c/(ev1c + ev2c));
else
printf("%.1lf\n", (double)((1 - pow(qp, ev1c)) * 100 )/(1 - pow(qp, ev1c + ev2c)) );
}

return 0;
}