結果

問題 No.76 回数の期待値で練習
ユーザー ctyl_0ctyl_0
提出日時 2015-10-03 02:48:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,253 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 84,340 KB
実行使用メモリ 10,756 KB
最終ジャッジ日時 2023-09-27 01:32:55
合計ジャッジ時間 1,305 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
10,756 KB
testcase_01 AC 19 ms
10,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << fixed << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main() {
    
    // source code
    vector<double> E(1000000);
    E[0] = 1.0000000000000000;
    E[1] = 1.0833333333333333;
    E[2] = 1.2569444444444444;
    E[3] = 1.5353009259259260;
    E[4] = 1.6915991512345676;
    E[5] = 2.0513639724794235;
    
    // 1:2:3:1:3:2
    vector<double> P(6);
    P[0] = 1.0 / 12;
    P[1] = 2.0 / 12;
    P[2] = 3.0 / 12;
    P[3] = 1.0 / 12;
    P[4] = 3.0 / 12;
    P[5] = 2.0 / 12;
    
    int T = inputValue();
    repd(i, 6, E.size()){
        E[i] = 0;
        rep(j, 6){
            E[i] += (1 + E[i - (j + 1)]) * P[j];
        }
    }
    
    rep(i, T){
        output(E[inputValue() - 1], 15);
    }
    
    return 0;
}
0