結果

問題 No.1429 Simple Dowsing
ユーザー materialmaterial
提出日時 2021-03-14 16:28:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 658 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 31,424 KB
平均クエリ数 3.00
最終ジャッジ日時 2023-09-24 10:08:24
合計ジャッジ時間 2,881 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
31,424 KB
testcase_01 AC 110 ms
31,028 KB
testcase_02 AC 108 ms
31,124 KB
testcase_03 AC 108 ms
31,056 KB
testcase_04 AC 108 ms
30,932 KB
testcase_05 AC 107 ms
30,692 KB
testcase_06 AC 107 ms
30,760 KB
testcase_07 AC 108 ms
31,056 KB
testcase_08 AC 108 ms
31,008 KB
testcase_09 AC 107 ms
31,044 KB
testcase_10 AC 106 ms
30,780 KB
testcase_11 AC 106 ms
31,272 KB
testcase_12 AC 105 ms
30,816 KB
testcase_13 AC 105 ms
30,732 KB
testcase_14 AC 106 ms
30,828 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def candidate(p, q, d)
  ts = []
  (0..100).each do |y|
    (0..100).each do |x|
      if ((p - x) ** 2 + (q - y) ** 2) == d then
        ts.push([x, y])
      end
    end
  end
  return ts
end

def intersection(s, t)
  u = []
  s.each do |x|
    u.push(x) if t.include?(x)
  end
  return u
end

def get_candidate(p, q)
  puts "? #{p} #{q}"
  STDOUT.flush

  d = gets.chomp.to_i

  return candidate(p, q, d)
end

def main(argv)
  p = 0
  q = 0

  ts1 = get_candidate(p, q)

  p = 0
  q = 100

  ts2 = get_candidate(p, q)

  ts = intersection(ts1, ts2)

  p = ts[0][0]
  q = ts[0][1]

  puts "! #{p} #{q}"
  STDOUT.flush
end

main(ARGV) if self.to_s == 'main'
0