結果

問題 No.58 イカサマなサイコロ
ユーザー なお
提出日時 2014-11-04 23:56:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2,260 ms / 5,000 ms
コード長 1,121 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 159,028 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 17:35:44
合計ジャッジ時間 26,631 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

// 想定解法: モンテカルロ

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
void rc(int v,int mn,int mx){if(v<mn||mx<v){cerr<<"error"<<endl;}}
const int MAX = 10;

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)) );
}
unsigned int xor128rnd(unsigned int m){
    return xor128() % m;
}

int main(){
    int N, K;
    cin >> N >> K;
    rc(N,1,MAX);
    rc(K,0,N);

    clock_t t = clock() + CLOCKS_PER_SEC * 2;
    int win = 0, total = 1;
    while(t >= clock()){
        int sum = 0;
        REP(i,N) sum += xor128rnd(6)+1;
        REP(i,N-K) sum -= xor128rnd(6)+1;
        REP(i,K) sum -= xor128rnd(3)+4;
        if(sum < 0) win++;
        total++;
    }

    cout << fixed << setprecision(9) << 1.0*win/total << endl;
    return 0;
}

/* 解説 
実際にシミュレーションして勝敗をカウントします。
2秒間くらいやれば正解にだいたい近づきます。
*/
0