結果

問題 No.75 回数の期待値の問題
ユーザー なおなお
提出日時 2014-11-24 00:06:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,090 ms / 5,000 ms
コード長 964 bytes
コンパイル時間 2,727 ms
コンパイル使用メモリ 150,608 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-30 22:36:37
合計ジャッジ時間 87,542 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define REPEAT(i, k, n)     for(int(i)=(k);(i)<((k)+(n));++(i))
#define EPS 1e-4

unsigned int xor128(void) {
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

int main(){
    int K;
    cin >> K;

    map<int,int> m;
    clock_t t = clock() + CLOCKS_PER_SEC * 4;
    int total = 0;
    while(t >= clock()){
        int c = 0, sum = 0;
        while(1){
            sum += xor128()%6+1;
            c++;
            if(sum == K) break;
            if(sum > K) sum = 0;
        }
        m[c]++;
        total++;
    }
    double res = 0;
    for(auto it = m.begin(); it != m.end(); ++it){
        res += it->first * ((double)it->second / total);
    }

    printf("%.12f\n", res);
    return 0;
}
0