結果
問題 |
No.75 回数の期待値の問題
|
ユーザー |
![]() |
提出日時 | 2017-05-29 23:48:58 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 13 ms / 5,000 ms |
コード長 | 723 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 41,728 KB |
実行使用メモリ | 9,344 KB |
最終ジャッジ日時 | 2024-09-21 18:15:22 |
合計ジャッジ時間 | 986 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#include<cstdio> #include<vector> using namespace std; using pid=pair<int,double>; using vd=vector<long double>; using vvd=vector<vd>; int main(void) { int k, i, j, l, n; vvd c; long double r=1.0/6, ans; while(scanf("%d", &k)==1) { c.resize(2000); for(auto&ce:c) ce.assign(k+1, 0.0); c[0][0]=1.0; for(i=1;i<c.size();i++) { for(j=0;j<k;j++) { for(l=1;l<=6;l++) { n=j+l; if(n>k) n=0; c[i][n]+=c[i-1][j]*r; } } } /* printf("--- dump start ---\n"); for(auto&ce:c) { for(auto cee:ce) printf("%.3f ", cee); printf("\n"); } printf("--- dump end ---\n"); */ ans=0.0; for(i=1;i<c.size();i++) { ans+=i*c[i][k]; } printf("%f\n" ,(double)ans); } return 0; }