結果
問題 | No.425 ジャンケンの必勝法 |
ユーザー |
👑 |
提出日時 | 2019-01-31 05:14:48 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 2,395 bytes |
コンパイル時間 | 2,899 ms |
コンパイル使用メモリ | 161,516 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-13 04:04:57 |
合計ジャッジ時間 | 4,629 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 18 |
ソースコード
import std.conv, std.functional, std.stdio, std.string;import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, 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; }bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1;(unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }enum N = 101;int P0, Q;void main() {try {for (; ; ) {P0 = readInt();Q = readInt();/*x[i] = (i/100) (1/2 + (1/2) x[i-Q]) + (1 - i/100) (1/3 + (1/3) x[i+Q])*/auto a = new real[][](N, N + 1);foreach (i; 0 .. N) {const p = i / 100.0L;a[i][] = 0.0;a[i][i] += 1.0;a[i][max(i - Q, 0)] -= p / 2.0;a[i][min(i + Q, N - 1)] -= (1.0 - p) / 3.0;a[i][N] += p / 2.0 + (1.0 - p) / 3.0;}foreach (h; 0 .. N) {foreach (i; h + 1 .. N) {if (abs(a[h][h]) < abs(a[i][h])) {swap(a[h], a[i]);}}assert(abs(a[h][h]) > 1e-10);foreach (j; h + 1 .. N + 1) {a[h][j] /= a[h][h];}a[h][h] = 1.0;foreach (i; h + 1 .. N) {foreach (j; h + 1 .. N + 1) {a[i][j] -= a[i][h] * a[h][j];}a[i][h] = 0.0;}}foreach_reverse (i; 0 .. N) {foreach (j; i + 1 .. N) {a[i][N] -= a[i][j] * a[j][N];}}real ans = 0.0;ans += 1.0L / 3.0;ans += 1.0L / 3.0 * a[P0][N];writefln("%.10f", ans);}} catch (EOFException e) {}}