結果

問題 No.75 回数の期待値の問題
ユーザー tubo28tubo28
提出日時 2014-11-23 23:57:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,526 ms / 5,000 ms
コード長 1,010 bytes
コンパイル時間 565 ms
コンパイル使用メモリ 66,392 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 22:33:44
合計ジャッジ時間 97,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,519 ms
4,380 KB
testcase_01 AC 4,520 ms
4,380 KB
testcase_02 AC 4,520 ms
4,380 KB
testcase_03 AC 4,520 ms
4,384 KB
testcase_04 AC 4,519 ms
4,380 KB
testcase_05 AC 4,526 ms
4,380 KB
testcase_06 AC 4,521 ms
4,376 KB
testcase_07 AC 4,520 ms
4,380 KB
testcase_08 AC 4,521 ms
4,380 KB
testcase_09 AC 4,519 ms
4,376 KB
testcase_10 AC 4,520 ms
4,380 KB
testcase_11 AC 4,519 ms
4,384 KB
testcase_12 AC 4,520 ms
4,376 KB
testcase_13 AC 4,520 ms
4,376 KB
testcase_14 AC 4,520 ms
4,380 KB
testcase_15 AC 4,523 ms
4,380 KB
testcase_16 AC 4,519 ms
4,376 KB
testcase_17 AC 4,520 ms
4,376 KB
testcase_18 AC 4,522 ms
4,380 KB
testcase_19 AC 4,521 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int K;
    while(cin>>K){
        double dp[2][222];
        rep(j,2)rep(i,222)dp[j][i]=0;
        dp[0][0]=1;
        double ans=0;
        clock_t start = clock();
        for(int t=1;;t++){
            rep(i,K+1)dp[(t&1)][i]=0;
            for(int i=0;i<K;i++){
                for(int j=1;j<=6;j++){
                    if(i+j>K) dp[(t&1)][0]  +=dp[1-(t&1)][i]/6;
                    else      dp[(t&1)][i+j]+=dp[1-(t&1)][i]/6;
                }
            }
            // for(int i=0;i<=10;i++){
            //     cout << dp[1-(t&1)][i] << " ";
            // }
            // cout << endl;
            ans+=dp[1-(t&1)][K]*t;
            clock_t end = clock();
            if((double)(end-start)/CLOCKS_PER_SEC > 4.5)break;
        }
        printf("%.20lf\n",ans-1);
    }
}
0