結果

問題 No.75 回数の期待値の問題
ユーザー pekempeypekempey
提出日時 2015-11-13 23:22:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,805 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 154,492 KB
実行使用メモリ 4,560 KB
最終ジャッジ日時 2023-10-11 16:37:20
合計ジャッジ時間 3,779 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

typedef long double D;

typedef vector<D> vec;
typedef vector<vec> mat;
mat mul(mat &A, mat &B) {
	mat res(A.size(), vec(B[0].size()));
	rep (i, A.size()) rep (j, B[0].size()) rep (k, A[0].size()) {
		res[i][j] += A[i][k] * B[k][j];
	}
	return res;
}
mat pow(mat A, ll b) {
	mat res(A.size(), vec(A.size()));
	rep (i, A.size()) res[i][i] = 1;
	while (b) {
		if (b & 1) res = mul(res, A);
		A = mul(A, A);
		b /= 2;
	}
	return res;
}
mat companion(vector<D> a) {
	int n = a.size();
	mat res(n + 1, vec(n + 1));
	rep (i, n - 1) res[i][i + 1] = 1;
	rep (i, n) res[n - 1][i] = a[i];
	res[n][1] = res[n][n] = 1;
	return res;
}
pair<D, D> calc(vector<D> a, vector<D> b, ll n) {
	int k = a.size();
	mat A = companion(a);
	A = pow(A, n);
	b.push_back(a[0]);
	D res = 0, sum = 0;
	rep (i, k) {
		res += A[0][i] * b[i];
		sum += A[k][i] * b[i];
	}
	return make_pair(res, sum);
}

int main() {
	int T;
	cin >> T;
	D p = 1.0 / 6;
	vector<D> a(6, p);
	rep (i_, T) {
		ll N;
		cin >> N;
		D low = 0, high = 1e4;
		rep (j_, 200) {
			D mid = (low + high) / 2;
			vector<D> b(6);
			b[4] = -mid;
			b[5] = mid * 5.0 / 6.0 + 1;
			D ret = calc(a, b, N + 4).second + mid;

			if (ret >= mid) {
				low = mid;
			} else {
				high = mid;
			}
		}
		printf("%.20f\n", (double)low);
	}
	return 0;
}
0