結果

問題 No.1793 実数当てゲーム
ユーザー ichinoseACichinoseAC
提出日時 2021-12-22 15:05:57
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 874 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 11,468 KB
実行使用メモリ 31,804 KB
平均クエリ数 966.61
最終ジャッジ日時 2023-10-14 15:16:46
合計ジャッジ時間 4,011 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Interactive
  def solve_exp
    if query(1)
      return -1
    end

    ok = 76
    ng = -1
    while (ok - ng).abs > 1
      mid = (ok + ng) / 2
      if query(10 ** mid)
        ok = mid
      else
        ng = mid
      end
    end
    ok
  end

  def solve
    exp = solve_exp

    ok = 1.0
    ng = 0
    while (ok - ng).abs > 0.00001
      mid = (ok + ng) / 2
      if query(mid * (10 ** exp))
        ok = mid
      else
        ng = mid
      end
    end

    ok * (10 ** exp)
  end

  def query(v)
    send_query(v)
    read
  end

  def send_query(v)
    @sent_query = v

    $stdout.puts "? %.10f" % v
    $stdout.flush
  end

  def read
    case $stdin.gets.chomp
    when /y/i
      true
    when /n/i
      false
    else
      raise
    end
  end
end

gets.to_i.times do
  ans = Interactive.new.solve
  $stdout.puts "! %.10f" % ans
  $stdout.flush
end
0