結果
| 問題 |
No.65 回数の期待値の練習
|
| コンテスト | |
| ユーザー |
ty70
|
| 提出日時 | 2015-06-08 15:00:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 2,050 bytes |
| コンパイル時間 | 756 ms |
| コンパイル使用メモリ | 87,516 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-06 14:45:52 |
| 合計ジャッジ時間 | 1,331 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#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;
}
ty70