結果

問題 No.75 回数の期待値の問題
ユーザー OUDONOUDON
提出日時 2017-10-01 18:30:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4,902 ms / 5,000 ms
コード長 1,643 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 166,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 23:20:14
合計ジャッジ時間 105,689 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

class TimeCheck {
public:
    TimeCheck(int _limit) : limit(_limit) {}

    void start()
    {
        start_at = std::chrono::system_clock::now();
    }

    bool check()
    {
        auto end_at = std::chrono::system_clock::now();
        double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_at - start_at).count(); 
        return (elapsed < limit);
    }

private:
    std::chrono::system_clock::time_point start_at;
    int limit;
};

int main()
{
    ios::sync_with_stdio(false);

    int K; cin >> K;

    random_device rand_dev;
    mt19937 rand_mt(rand_dev());
    uniform_int_distribution<int> dice(1, 6);

    ll step_sum = 0, ok_num = 0;

    TimeCheck time(4900);
    time.start();
    while (time.check()) {
        int sum = 0, cnt = 0;
        while (sum != K) {
            sum += dice(rand_mt);
            cnt++;

            if (sum > K) sum = 0;
        }

        step_sum += cnt;
        ok_num++;

#ifdef DEBUG
        cerr << cnt << endl;
#endif
    }

    cout << (double)step_sum / ok_num << endl;
}
0