結果
| 問題 |
No.301 サイコロで確率問題 (1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-18 07:23:49 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,572 bytes |
| コンパイル時間 | 2,531 ms |
| コンパイル使用メモリ | 167,372 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-06-13 02:55:56 |
| 合計ジャッジ時間 | 3,818 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 1 |
ソースコード
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }
alias P = Tuple!(real[], real);
P multiply(P a, P b) {
P ret = tuple(new real[11], 0.0);
ret[0][] = 0.0;
foreach (i; 0 .. 6) foreach (j; 0 .. 6) {
ret[0][i + j] += a[0][i] * b[0][j];
}
ret[1] = a[0].sum * b[1] + a[1];
foreach_reverse (i; 6 .. 11) {
foreach (j; 1 .. 7) {
ret[0][i - j] += ret[0][i] / 6.0;
}
ret[1] += ret[0][i];
}
ret[0].length = 6;
return ret;
}
long N;
void main() {
auto x = new real[7];
auto y = new real[7];
x[] = 0.0;
y[] = 0.0;
foreach (i; 1 .. 7) {
x[i] += 1.0;
foreach (j; 1 .. 7) {
if (i - j >= 0) {
x[i] += x[i - j] / 6.0;
y[i] += y[i - j] / 6.0;
} else {
y[i] += 1.0 / 6.0;
}
}
}
try {
for (; ; ) {
const T = readInt();
foreach (caseId; 0 .. T) {
N = readLong();
P a = tuple(new real[6], 0.0);
a[0][] = 0.0;
a[0][0] = 1.0;
foreach_reverse (h; 0 .. bsr(N) + 1) {
a = multiply(a, a);
if ((N >> h) & 1) {
a[0] = 0.0 ~ a[0];
foreach (i; 0 .. 6) {
a[0][i] += a[0][6] / 6.0;
}
a[1] += a[0][6];
a[0].length = 6;
}
}
debug {
writeln(a);
}
real xx = a[1], yy = 0.0;
foreach (i; 0 .. 6) {
xx += a[0][i] * x[i];
yy += a[0][i] * y[i];
}
const ans = xx / (1.0 - yy);
writefln("%.20f", ans);
}
}
} catch (EOFException e) {
}
}