結果

問題 No.75 回数の期待値の問題
ユーザー なお
提出日時 2014-11-24 00:06:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4,207 ms / 5,000 ms
コード長 964 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 161,724 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-02 20:57:38
合計ジャッジ時間 90,463 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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