Created
October 15, 2017 10:30
-
-
Save whatalnk/46f07440217eed7c166985990e4e2dc1 to your computer and use it in GitHub Desktop.
AtCoder ARC #042 B - アリの高橋くん
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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