結果

問題 No.75 回数の期待値の問題
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-07-28 10:35:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,337 bytes
コンパイル時間 1,860 ms
コンパイル使用メモリ 171,516 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 11:34:17
合計ジャッジ時間 2,853 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
template <typename T> void gaussianElimination(vector<vector<T>> &A)
{
    int N = A.size();
    int M = A[0].size();
    assert(N <= M);

    int k = 0;
    for (int i = 0; i < N; i++) {
        int v = -1;
        for (int j = k; j < N && v == -1; j++) {
            if (A[j][i] != 0) {
                v = j;
            }
        }
        if (v == -1) continue;
        //a[i] = k;
        swap(A[k], A[v]);
        T x = A[k][i];
        for (int j = 0; j < M; j++)
            A[k][j] = A[k][j] / x;
        for (int j = k + 1; j < N; j++) {
            for (int h = M - 1; h >= i; h--)
                A[j][h] = A[j][h] - A[k][h] * A[j][i];
        }
        k++;
    }
}
template <typename T> void print(vector<vector<T>> &A) {
    int N = A.size(); int M = A[0].size();

    rep(y, 0, N) {
        rep(x, 0, M) cout << A[y][x] << "\t";
        cout << endl;
    }
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/








int K;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> K;

    vector<vector<double>> A(K, vector<double>(K + 1, 0));

    rep(i, 0, K) {
        rep(j, 1, 7) {
            int next = (i + j > K) ? 0 : i + j;
            A[i][K] -= 1.0 / 6;
            if (i + j != K) A[i][next] += 1.0 / 6;
        }
        A[i][i] -= 1;
    }

    
    print(A);
    gaussianElimination(A);
    print(A);

    double ans = A[0][K];
    printf("%.10f\n", ans);
}
0