結果

問題 No.1793 実数当てゲーム
ユーザー to-omerto-omer
提出日時 2021-11-09 21:12:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 24,688 KB
平均クエリ数 2230.56
最終ジャッジ日時 2023-10-13 19:56:45
合計ジャッジ時間 4,040 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
24,688 KB
testcase_01 AC 64 ms
24,320 KB
testcase_02 AC 147 ms
24,076 KB
testcase_03 AC 144 ms
24,348 KB
testcase_04 AC 146 ms
24,476 KB
testcase_05 AC 142 ms
24,436 KB
testcase_06 AC 142 ms
24,660 KB
testcase_07 AC 142 ms
24,244 KB
testcase_08 AC 141 ms
24,512 KB
testcase_09 AC 142 ms
24,504 KB
testcase_10 AC 143 ms
24,116 KB
testcase_11 AC 142 ms
24,172 KB
testcase_12 AC 147 ms
24,472 KB
testcase_13 AC 151 ms
24,376 KB
testcase_14 AC 151 ms
24,640 KB
testcase_15 AC 146 ms
24,344 KB
testcase_16 AC 149 ms
24,352 KB
testcase_17 AC 147 ms
24,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
from sys import stdout


def query(s: str) -> str:
    print("?", s)
    stdout.flush()
    res = input().rstrip()
    if res == "-1":
        exit(0)
    return res == "Yes"


def answer(s: str):
    print("!", s)
    stdout.flush()


def float2string(f: float) -> str:
    s = f"{f:0.10f}"
    return s[0] + s[1:].rstrip("0").rstrip(".")


def middle(left: float, right: float, threshold: float = 1, last=False) -> float:
    if left < threshold and right > threshold:
        return threshold
    elif left < threshold:
        return (left + right) / 2
    elif last:
        return 2 * right * left / (right + left)
    else:
        return sqrt(left * right)


def solve():
    threshold = 167.7717663

    left = 0.0
    right = 12.22e74
    for _ in range(24):
        mid = middle(left, right, threshold)
        if query(float2string(mid)):
            left = mid
        else:
            right = mid
    return answer(float2string(middle(left, right, threshold, True)))


def main():
    T = int(input())
    for _ in range(T):
        solve()


if __name__ == "__main__":
    main()
0