-
Notifications
You must be signed in to change notification settings - Fork 0
/
2786.rb
80 lines (65 loc) · 1.37 KB
/
2786.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class Point
attr_reader :x, :y
def initialize(x, y)
@x = x.to_f
@y = y.to_f
end
def distance(other)
self.class.distance self, other
end
def distance2(other)
self.class.distance2 self, other
end
def inner_product(other)
self.class.inner_product self, other
end
def self.distance(a, b)
Math.sqrt(distance2 a, b)
end
def self.distance2(a, b)
(b.x - a.x) ** 2 + (b.y - a.y) ** 2
end
def self.inner_product(a, b)
a.x * b.x + a.y * b.y
end
end
class Circle < Point
attr_reader :c, :x, :y, :r
def initialize(x, y, r)
@c = Point.new x, y
@x = @c.x
@y = @c.y
@r = r.to_f
end
# 円と線分の交差判定
# @param [Point] a 線分の端点A
# @param [Point] b 線分の端点B
# @return [TrueClass | FalseClass]
def cross?(a, b)
a.inner_product(@c)
end
def interference(point)
d = distance2 point
r = @r ** 2
if d < r
1 # 円の内にある
elsif d == r
0 # 円周上にある
else
-1 # 円の外にある
end
end
end
result = []
gets.chomp.split(' ').each do |param|
tmp, cx, cy, r, ax, ay, bx, by = param.match %r{\((\d+),(\d+)\)(\d+)/\((\d+),(\d+)\)\((\d+),(\d+)\)}
c = Circle.new cx, cy, r
a = Point.new ax, ay
b = Point.new bx, by
ia = c.interference a
ib = c.interference b
if ia == 1 && ib == 1
result << 'A'
next
end
end