結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
31,420 KB
testcase_01 AC 106 ms
31,292 KB
testcase_02 WA -
testcase_03 AC 117 ms
31,272 KB
testcase_04 AC 112 ms
30,772 KB
testcase_05 WA -
testcase_06 AC 110 ms
30,876 KB
testcase_07 AC 109 ms
31,360 KB
testcase_08 AC 109 ms
31,012 KB
testcase_09 AC 110 ms
31,148 KB
testcase_10 AC 108 ms
31,112 KB
testcase_11 AC 109 ms
31,048 KB
testcase_12 AC 110 ms
31,528 KB
testcase_13 AC 110 ms
31,356 KB
testcase_14 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = 50
  q = 50

  ts1 = get_candidate(p, q)

  p = ts1[0][0]
  q = ts1[0][1]

  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