結果
問題 | No.301 サイコロで確率問題 (1) |
ユーザー | te-sh |
提出日時 | 2017-06-12 14:31:10 |
言語 | D (dmd 2.106.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,955 bytes |
コンパイル時間 | 2,832 ms |
コンパイル使用メモリ | 151,356 KB |
実行使用メモリ | 17,088 KB |
最終ジャッジ日時 | 2024-06-12 19:58:09 |
合計ジャッジ時間 | 7,135 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; // allowable-error: 10 ** -12 void main() { auto n = readln.chomp.to!size_t; foreach (_; 0..n) { auto k = readln.chomp.to!int; auto eps = real(10.0 ^^ (-13)); auto lower(real _, real a) { return calcE0(k, a) < a; } auto r = real(1); while (!lower(0, r)) r *= 2; auto m = iota(r / 2, r, eps).assumeSorted!lower.upperBound(0); writefln("%.13f", m.front); } } auto calcE0(int k, real m) { auto e0 = [0, m, m, m, m, m, 1]; auto p = real(1)/6, u = real(1); auto a = [[p,p,p,p,p,p,u], [u,0,0,0,0,0,0], [0,u,0,0,0,0,0], [0,0,u,0,0,0,0], [0,0,0,u,0,0,0], [0,0,0,0,u,0,0], [0,0,0,0,0,0,u]]; auto i = [[u,0,0,0,0,0,0], [0,u,0,0,0,0,0], [0,0,u,0,0,0,0], [0,0,0,u,0,0,0], [0,0,0,0,u,0,0], [0,0,0,0,0,u,0], [0,0,0,0,0,0,u]]; auto ak = repeatedSquare!(real[][], matMul)(a, k, i); return matMulVec(ak, e0)[0]; } T[][] matMul(T)(T[][] a, T[][] b) { import std.traits; auto l = b.length, m = a.length, n = b[0].length; auto c = new T[][](m, n); static if (isFloatingPoint!T) { foreach (ref r; c) r[] = T(0); } foreach (i; 0..m) foreach (j; 0..n) foreach (k; 0..l) c[i][j] += a[i][k] * b[k][j]; return c; } T[] matMulVec(T)(T[][] a, T[] b) { import std.traits; auto l = b.length, m = a.length; auto c = new T[](m); static if (isFloatingPoint!T) { c[] = T(0); } foreach (i; 0..m) foreach (j; 0..l) c[i] += a[i][j] * b[j]; return c; } T repeatedSquare(T, alias pred = "a * b", U)(T a, U n, T init) { import std.functional; alias predFun = binaryFun!pred; if (n == 0) return init; auto r = init; while (n > 0) { if ((n & 1) == 1) r = predFun(r, a); a = predFun(a, a); n >>= 1; } return r; }