Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 15, 2017 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/46f07440217eed7c166985990e4e2dc1 to your computer and use it in GitHub Desktop.
Save whatalnk/46f07440217eed7c166985990e4e2dc1 to your computer and use it in GitHub Desktop.
AtCoder ARC #042 B - アリの高橋くん
x0, y0 = gets.chomp.split(" ").map(&:to_f)
N = gets.chomp.to_i
points = []
N.times do
points << gets.chomp.split(" ").map(&:to_f)
end
points << points[0]
ans = (2<<17).to_f
N.times do |i|
x1, y1 = points[i]
x2, y2 = points[i+1]
x2 -= x1
y2 -= y1
x = x0 - x1
y = y0 - y1
d = (x * y2 - y * x2).abs / Math.sqrt(x2**2 + y2**2)
ans = d if d < ans
end
puts ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment