Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d8f0e6

Browse files
authored
Update minimum-number-of-lines-to-cover-points.py
1 parent292c3a3 commit8d8f0e6

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

‎Python/minimum-number-of-lines-to-cover-points.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ def ceil_divide(a, b):
3232
x2,y2=points[j]
3333
# (x-x1)/(x2-x1) = (y-y1)/(y2-y1)
3434
# => (y2-y1)x - (x2-x1)y = x1(y2-y1) - y1(x2-x1)
35-
a,b,c= (y2-y1),-(x2-x1),x1*(y2-y1)-y1*(x2-x1)
36-
g=gcd(gcd(a,b),c)
37-
a,b,c=a//g,b//g,c//g
38-
forxin (a,b,c):
39-
ifx!=0:
40-
ifx<0:
41-
a,b,c=-a,-b,-c
42-
break
35+
dx,dy=x2-x1,y2-y1
36+
g=gcd(dx,dy)
37+
a,b=dx//g,dy//g
38+
ifa<0or (a==0andb<0):
39+
a,b=-a,-b
40+
c=b*x1-a*y1
4341
lookup[(a,b,c)].add((x1,y1))
4442
lookup[(a,b,c)].add((x2,y2))
4543
lines= [lforl,pinlookup.iteritems()iflen(p)>2]# filter to improve complexity

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp