Created
December 8, 2012 09:04
-
-
Save coderaven/4239412 to your computer and use it in GitHub Desktop.
Solution for Devcon C-Cup Problem A
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
gets.to_i.times do | |
q = gets.to_i | |
sum_x, sum_y, sum_x2, sum_xy = 0, 0, 0, 0 | |
q.times do | |
x,y=gets.split.map(&:to_f) | |
sum_x += x | |
sum_y += y | |
sum_x2 += x**2 | |
sum_xy += x*y | |
end | |
mx = sum_x / q | |
my = sum_y / q | |
a = (sum_xy - sum_x * my) / (sum_x2 - sum_x * mx) | |
b = my - a * mx | |
a,b = [a,b].map {|p| p.to_i == p ? p.to_i : (p * 100).floor / 100.0} | |
puts "#{a} #{b}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment