結果
問題 | No.65 回数の期待値の練習 |
ユーザー | ty70 |
提出日時 | 2015-06-08 15:00:39 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 2,050 bytes |
コンパイル時間 | 612 ms |
コンパイル使用メモリ | 85,904 KB |
実行使用メモリ | 4,500 KB |
最終ジャッジ日時 | 2023-09-20 19:50:31 |
合計ジャッジ時間 | 1,589 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 2 ms
4,376 KB |
testcase_17 | AC | 1 ms
4,376 KB |
testcase_18 | AC | 1 ms
4,376 KB |
testcase_19 | AC | 1 ms
4,500 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <algorithm> // require sort next_permutation count __gcd reverse etc. #include <cstdlib> // require abs exit atof atoi #include <cstdio> // require scanf printf #include <functional> #include <numeric> // require accumulate #include <cmath> // require fabs #include <climits> #include <limits> #include <cfloat> #include <iomanip> // require setw #include <sstream> // require stringstream #include <cstring> // require memset #include <cctype> // require tolower, toupper #include <fstream> // require freopen #include <ctime> // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair<int, int> P; /* No.65 回数の期待値の練習 No.72 の確率固定版。 E[1] = 1 E[2] = E[1]*P1 + 1 = E[1]/6 + 1 E[3] = E[2]*P1 + E[1]*P2 + 1 = (E[2] + E[1] )/6 + 1 E[4] = E[3]*P1 + E[2]*P2 + E[1]*P3 + 1 = (E[3] + E[2] + E[1] )/6 + 1 E[5] = E[4]*P1 + E[3]*P2 + E[2]*P3 + E[1]*P4 + 1 = (E[4] + E[3] + E[2] + E[1] )/6 + 1 E[6] = E[5]*P1 + E[4]*P2 + E[3]*P3 + E[2]*P4 + E[1]*P5 + 1 = (E[5] + E[4] + E[3] + E[2] + E[1] )/6 + 1 E[7] = E[6]*P1 + E[5]*P2 + E[4]*P3 + E[3]*P4 + E[2]*P5 + E[1]*P6 + 1 = (E[6] + E[5] + E[4] + E[3] + E[2] + E[1] )/6 + 1 問題文は x >= 7 のとき E[x] = E[x-1]*1/6 + E[x-2]*1/6 + E[x-3]*1/6 + E[x-4]*1/6 + E[x-5]*1/6 + E[x-6]*1/6 + 1 の誤植かな? */ const int MAX_K = 22; double E[MAX_K]; int main() { memset (E, 0., sizeof (E ) ); ios_base::sync_with_stdio(0); E[1] = 1.; E[2] = E[1]/6. + 1.; E[3] = (E[2] + E[1] )/6. + 1.; E[4] = (E[3] + E[2] + E[1] )/6. + 1.; E[5] = (E[4] + E[3] + E[2] + E[1] )/6. + 1.; E[6] = (E[5] + E[4] + E[3] + E[2] + E[1] )/6. + 1.; for (int i = 7; i < MAX_K; i++ ){ for (int j = 1; j <= 6; j++ ){ E[i] += E[i-j]/6.; } // end for E[i] += 1.; } // end for int K; cin >> K; printf ("%.6lf\n", E[K] ); return 0; }