結果

問題 No.1793 実数当てゲーム
コンテスト
ユーザー to-omer
提出日時 2021-11-09 21:12:45
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,118 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 321 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 35,468 KB
平均クエリ数 2230.56
最終ジャッジ日時 2026-04-15 04:13:06
合計ジャッジ時間 4,473 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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