# What is the Probability!!(UVA10056) ## [程式繳交區](https://hackmd.io/@Renektonn/ryuRZ1AwJe/edit) ## 題目 [點我](https://onlinejudge.org/external/100/10056.pdf) ## 解題網站 [UVA](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=997) [ZJ](https://zerojudge.tw/ShowProblem?problemid=e510) ## 想法 $\frac{1}{6}+\frac{5}{6}\times \frac{5}{6}\times \frac{1}{6} + ...$ $a1\times \frac{1-r^n}{1-r}, r < 1,n\to\infty$ $=\frac{1}{6}\times \frac{1-(\frac{25}{36})^n}{1-\frac{25}{36}}, r < 1,n\to\infty$ $=p\times \frac{1}{1-r}, r < 1$ $=\frac{1}{6}\times \frac{36}{11}$ $=\frac{6}{11}$ ## 需要推導的演算法 ``` 1. 輸入s 2. 重複s次 2.1 輸入n,p,player 2.2 r = (1-p)^n 2.3 輸出(p/(1-r))*(1-p)^(player-1) ``` ## 上述演算法的程式碼 ```cpp= #include <bits/stdc++.h> using namespace std; int main() { int s; cin >> s; while (s--) { int n, player; double p; cin >> n >> p >> player; if (p == 0) { printf("%.4f\n", 0.0); continue; } double r = pow(1 - p, n); double ans = p / (1 - r) * pow(1 - p, player - 1); printf("%.4f\n", ans); } return 0; } ``` :::info 此題重點在於推導,不在於寫程式,若僅為了CPE考試,可將它背起來 :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up