結果

問題 No.75 回数の期待値の問題
ユーザー koyoprokoyopro
提出日時 2015-10-01 15:46:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,396 ms / 5,000 ms
コード長 525 bytes
コンパイル時間 1,264 ms
コンパイル使用メモリ 143,488 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 01:13:09
合計ジャッジ時間 12,036 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
4,384 KB
testcase_01 AC 84 ms
4,384 KB
testcase_02 AC 84 ms
4,380 KB
testcase_03 AC 133 ms
4,384 KB
testcase_04 AC 85 ms
4,380 KB
testcase_05 AC 84 ms
4,380 KB
testcase_06 AC 82 ms
4,384 KB
testcase_07 AC 135 ms
4,380 KB
testcase_08 AC 145 ms
4,380 KB
testcase_09 AC 151 ms
4,380 KB
testcase_10 AC 159 ms
4,380 KB
testcase_11 AC 174 ms
4,384 KB
testcase_12 AC 191 ms
4,380 KB
testcase_13 AC 203 ms
4,380 KB
testcase_14 AC 212 ms
4,380 KB
testcase_15 AC 272 ms
4,384 KB
testcase_16 AC 1,035 ms
4,380 KB
testcase_17 AC 1,859 ms
4,384 KB
testcase_18 AC 2,228 ms
4,380 KB
testcase_19 AC 2,396 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(int i=0; i<(n); i++)

int K;
signed main()
{
    cin >> K;
    double ret = 0;
    int trynum = 1e6;
    REP(i,trynum) {
        int s = 0;
        int cnt = 0;
        while(true) {
            s += 1 + rand() % 6;
            cnt++;
            if (s == K) {
                ret += 1.0 * cnt / trynum;
                break;
            } else if (s > K) {
                s = 0;
            }
        }
    }
    printf("%.14f\n", ret);
    return 0;
}
0