結果

問題 No.75 回数の期待値の問題
ユーザー Mi_SawaMi_Sawa
提出日時 2015-09-26 17:26:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,503 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 147,428 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 16:35:09
合計ジャッジ時間 2,555 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define all(x) begin(x),end(x)
#define rall(x) (x).rbegin(),(x).rend()
#define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define repsz(i,v) rep(i,(v).size())
#define aur auto&
#define bit(n) (1LL<<(n))
#define eb emplace_back
#define mt make_tuple
#define fst first
#define snd second
using namespace std;
typedef long long ll;
//#define int long long
template<class C>int size(const C &c){ return c.size(); }
template<class T>bool chmin(T&a,const T&b){if(a<=b)return false;a=b;return true;}
template<class T>bool chmax(T&a,const T&b){if(a>=b)return false;a=b;return true;}

bool solve(){
    int k; cin >> k;
    using R = long double;
    vector<R> prob(k+6);
    prob[0] = 1;
    rep(i, k) REP(j, 1, 7) prob[i+j] += prob[i] / 6.;

    vector<R> expect(k+6);
    expect[0] = 0;
    rep(i, k+6) if(i){
        R sum = 0;
        for(int j = max(0, i-6); j < min(i, k); ++j) sum += prob[j];
        for(int j = max(0, i-6); j < min(i, k); ++j) expect[i] += (prob[j] / sum) * (expect[j] + 1);
    }
    R ans = expect[k];
    R num = 1 / prob[k] - 1;
    R sum = 1 - prob[k];
    for(int i = k+1; i < k+6; ++i) ans += num * (prob[i] / sum) * expect[i];
    cout << ans << endl;
    return true;
}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}
// vim:set foldmethod=marker commentstring=//%s:
0