为独立老师和小型培训机构开发的上课记录统计工具
Getting Support:
Mail: zxzdev0@gmail.com
QQ: 1002863699
Idea, Suggestions or Feedback:
Mail: zxzdev0.feedback@gmail.com
或在文章下方留言。
or leave comment below.
# 防止被csdn判定为广告插一段代码
import math
def get_kb_str(dy_, dx_, x0, y0):
kx = dx_
ky = dy_
if kx < 0:
kx = -kx
ky = -ky
b_str = str(y0 * kx - ky * x0) + "/" + str(kx)
k_str = str(ky) + "/" + str(kx)
return k_str + "&" + b_str
def gcd_(a, b):
if b == 0:
return a
else:
return gcd_(b, a % b)
def solution(A):
UPPER = 10000
LOWER = 0
MAX_ANS = 100000000
ans = 0
handled_line = dict()
matrix = [[False] * UPPER for _ in range(UPPER)]
max_y = -1
max_x = -1
min_y = UPPER + 100
min_x = UPPER + 100
for point in A:
matrix[point.x][point.y] = True
if point.x > max_x:
max_x = point.x
if point.y > max_y:
max_y = point.y
if point.x < min_x:
min_x = point.x
if point.y < min_y:
min_y = point.y
for i in range(0, len(A)):
for j in range(i + 1, len(A)):
p1 = A[i]
p2 = A[j]
dy = p1.y - p2.y
dx = p1.x - p2.x
tmp = gcd_(dy, dx)
dy = int(dy / tmp)
dx = int(dx / tmp)
kb_str = get_kb_str(dy, dx, p1.x, p1.y)
if kb_str in handled_line:
continue
else:
handled_line[kb_str] = True
count = 1
new_x = p1.x + dx
new_y = p1.y + dy
while max_x >= new_x >= min_x and max_y >= new_y >= min_y:
if matrix[new_x][new_y]:
count += 1
new_x += dx
new_y += dy
new_x = p1.x - dx
new_y = p1.y - dy
while max_x >= new_x >= min_x and max_y >= new_y >= min_y:
if matrix[new_x][new_y]:
count += 1
new_x -= dx
new_y -= dy
if count > 2:
ans += math.factorial(count)//(math.factorial(3)*math.factorial(count-3))
if ans > MAX_ANS:
return -1
return ans
def trans(A):
res = []
for item in A:
x = Point2D()
x.x = item[0]
x.y = item[1]
res.append(x)
return res