Problem:


Parallel/Orthogonal

For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.

s1 crosses points p0 and p1, and
s2 crosses points p2 and p3.

Input

The entire input looks like:

q (the number of queries)
1st query
2nd query
...
qth query

Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:

xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3

Output

For each query, print "2", "1" or "0".

Constraints

1 ≤ q ≤ 1000

-10000 ≤ xpi, ypi ≤ 10000

p0 &ne; p1 and
p2 &ne; p3.

Sample Input 1

3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2

Sample Output 1

2
1
0



Sample input:
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2


Sample output:
2
1
0

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
    if x1 - x0 == 0:
        if x3 -x2 == 0:
            print('2')
        elif y3 - y2 == 0:
            print('1')
        else:
            print('0')
    elif x3 - x2 == 0:
        if y1 - y0 == 0:
            print('1')
        else:
            print('0')
    else:
        a1 = (y1-y0)/(x1-x0)
        a2 = (y3-y2)/(x3-x2)
        if a1 * a2 == 1:
            print('1')
        elif a1 == a2 or a1 == -a2:
            print('2')
        else:
            print('0')

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
    if x1 - x0 == 0:
        if x3 -x2 == 0:
            print('2')
        elif y3 - y2 == 0:
            print('1')
        else:
            print('0')
    elif x3 - x2 == 0:
        if y1 - y0 == 0:
            print('1')
        else:
            print('0')
    else:
        a1 = (y1-y0)/(x1-x0)
        a2 = (y3-y2)/(x3-x2)
        if a1 * a2 == -1:
            print('1')
        elif a1 == a2 or a1 == -a2:
            print('2')
        else:
            print('0')

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
    if x1 - x0 == 0:
        if x3 -x2 == 0:
            print('2')
        elif y3 - y2 == 0:
            print('1')
        else:
            print('0')
    elif x3 - x2 == 0:
        if y1 - y0 == 0:
            print('1')
        else:
            print('0')
    elif y1 - y0 == 0:
        if y3 - y2 == 0:
            print('2')
        elif x3 - x2 == 0:
            print('1')
        else:
            print('0')
    else:
        a1 = (y1-y0)/(x1-x0)
        a2 = (y3-y2)/(x3-x2)
        if a1 * a2 == -1:
            print('1')
        elif a1 == a2 or a1 == -a2:
            print('2')
        else:
            print('0')

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
    if x1 - x0 == 0:
        if x3 -x2 == 0:
            print('2')
        elif y3 - y2 == 0:
            print('1')
        else:
            print('0')
    elif x3 - x2 == 0:
        if y1 - y0 == 0:
            print('1')
        else:
            print('0')
    elif y1 - y0 == 0:
        if y3 - y2 == 0:
            print('2')
        elif x3 - x2 == 0:
            print('1')
        else:
            print('0')
    elif y3 - y2 == 0:
        if x1 - x0 == 0:
            print('1')
        else:
            print('0')
    else:
        a1 = (y1-y0)/(x1-x0)
        a2 = (y3-y2)/(x3-x2)
        if a1 * a2 == -1:
            print('1')
        elif a1 == a2 or a1 == -a2:
            print('2')
        else:
            print('0')

Submission status: Wrong Answer

Solution code:
n = int(input())
def judge():
    x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
    if x1 - x0 == 0:
        if x3 -x2 == 0:
            print('2')
        elif y3 - y2 == 0:
            print('1')
        else:
            print('0')
    elif x3 - x2 == 0:
        if y1 - y0 == 0:
            print('1')
        else:
            print('0')
    elif y1 - y0 == 0:
        if y3 - y2 == 0:
            print('2')
        elif x3 - x2 == 0:
            print('1')
        else:
            print('0')
    elif y3 - y2 == 0:
        if x1 - x0 == 0:
            print('1')
        else:
            print('0')
    else:
        a1 = (y1-y0)/(x1-x0)
        a2 = (y3-y2)/(x3-x2)
        if a1 * a2 == -1:
            print('1')
        elif a1 == a2 or a1 == -a2:
            print('2')
        else:
            print('0')

for i in range(n):
    judge()

Submission status: Wrong Answer

Solution code:
def judge(x):
    x0,y0,x1,y1,x2,y2,x3,y3 = map(float,x.split())
    if x1 - x0 == 0:
        if x3 -x2 == 0:
            print('2')
        elif y3 - y2 == 0:
            print('1')
        else:
            print('0')
    elif x3 - x2 == 0:
        if y1 - y0 == 0:
            print('1')
        else:
            print('0')
    elif y1 - y0 == 0:
        if y3 - y2 == 0:
            print('2')
        elif x3 - x2 == 0:
            print('1')
        else:
            print('0')
    elif y3 - y2 == 0:
        if x1 - x0 == 0:
            print('1')
        else:
            print('0')
    else:
        a1 = (y1-y0)/(x1-x0)
        a2 = (y3-y2)/(x3-x2)
        if a1 * a2 == -1:
            print('1')
        elif a1 == a2 or a1 == -a2:
            print('2')
        else:
            print('0')
n = int(input())            
q = ['']*n
for i in range(n):
    q[i] = input()
for i in range(n):        
    judge(q[i])

Submission status: Wrong Answer

Solution code:
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]

q = int(input())
for i in range(q):
    x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
    a = [x1-x0,y1-y0]
    b = [x3-x2,y3-y1]
    if dot(a,b) == 0 : print(1)
    elif cross(a,b) == 0 : print(2)
    else : print(0)

Submission status: Wrong Answer

Solution code:
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]

q = int(input())
for i in range(q):
    x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
    a = [x1-x0,y1-y0]
    b = [x3-x2,y3-y2]
    if dot(a,b) == 0 : print(1)
    elif cross(a,b) == 0 : print(2)
    else : print(0)
    print(a,b,dot(a,b))

Submission status: Wrong Answer

Solution code:
n = int(input())

def dot(a,b):
    return a[0] * b[0] + a[1] * b[1]

from math import sqrt
def s(a):
    return sqrt(a[0]**2 + a[1]**2)

for i in range(n):
    points = [int(j) for j in input().split()]
    p0 = points[:2]
    p1 = points[2:4]
    a = [p0[0]-p1[0],p0[1]-p1[1]]
    p2 = points[4:6]
    p3 = points[6:8]
    b = [p2[0]-p3[0],p2[1]-p3[1]]
    c = dot(a,b)/(s(a) * s(b))
    if c == 0:
        print(1)
    elif c == 1:
        print(2)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

class Line():
    def __init__(self, x1, y1, x2, y2):
        self.p1 = Point(x1, y1)
        self.p2 = Point(x2, y2)

    def get_slope(self):
        if self.p1.x == self.p2.x:
            return float('inf')
        return (self.p2.y - self.p1.y)/(self.p2.x - self.p1.x)

q = int(input())
for i in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split(' ')))
    line1, line2 = Line(x0, y0, x1, y1), Line(x2, y2, x3, y3)
    a1, a2 = round(line1.get_slope(), 8), round(line2.get_slope(), 8)
    if a1 == a2: # 平行
        print('2')
    elif a1*a2 == -1:
        print('1')
    elif (a1 == float('inf') and a2 == 0) or (a1 == 0 and a2 == float('inf')):
        print('1')
    else:
        print('0')

Submission status: Wrong Answer

Solution code:
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

class Line():
    def __init__(self, x1, y1, x2, y2):
        self.p1 = Point(x1, y1)
        self.p2 = Point(x2, y2)

    def get_slope(self):
        if self.p1.x == self.p2.x:
            return float('inf')
        return (self.p2.y - self.p1.y)/(self.p2.x - self.p1.x)

q = int(input())
for i in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split(' ')))
    line1, line2 = Line(x0, y0, x1, y1), Line(x2, y2, x3, y3)
    a1, a2 = line1.get_slope(), line2.get_slope()
    if a1 == a2: # 平行
        print('2')
    elif a1*a2 == -1.0:
        print('1')
    elif (a1 == float('inf') and a2 == 0) or (a1 == 0 and a2 == float('inf')):
        print('1')
    else:
        print('0')

Submission status: Wrong Answer

Solution code:
# coding=utf-8


def line_slope(line_from, line_to):
    try:
        slope = (line_to[1] - line_from[1])/(line_to[0] - line_from[1])
    except ZeroDivisionError:
        slope = "未定義"
    return slope


def is_parallel(l_from1, l_to1, l_from2, l_to2):
    slope1 = line_slope(l_from1, l_to1)
    slope2 = line_slope(l_from2, l_to2)
    if slope1 == slope2:
        return 1
    return 0


def is_orthogonal(l_from1, l_to1, l_from2, l_to2):
    slope1 = line_slope(l_from1, l_to1)
    slope2 = line_slope(l_from2, l_to2)
    if slope1 == "未定義":
        if slope2 == 0:
            return 1
        return 0
    if slope2 == "未定義":
        if slope1 == 0:
            return 1
        return 0
    if slope1 * slope2 == -1:
        return 1
    return 0


if __name__ == '__main__':
    Q = int(input())

    for i in range(Q):
        all_list = list(map(int, input().split()))
        p0_list = all_list[:2]
        p1_list = all_list[2:4]
        p2_list = all_list[4:6]
        p3_list = all_list[6:]

        if is_parallel(p0_list, p1_list, p2_list, p3_list):
            print("2")
        elif is_orthogonal(p0_list, p1_list, p2_list, p3_list):
            print("1")
        else:
            print("0")

Submission status: Wrong Answer

Solution code:
# coding=utf-8


def line_slope(line_from, line_to):
    try:
        slope = (line_to[1] - line_from[1])/(line_to[0] - line_from[0])
    except ZeroDivisionError:
        slope = "未定義"
    return slope


def is_parallel(l_from1, l_to1, l_from2, l_to2):
    slope1 = line_slope(l_from1, l_to1)
    slope2 = line_slope(l_from2, l_to2)
    if slope1 == slope2:
        return 1
    return 0


def is_orthogonal(l_from1, l_to1, l_from2, l_to2):
    slope1 = line_slope(l_from1, l_to1)
    slope2 = line_slope(l_from2, l_to2)
    if slope1 == "未定義":
        if slope2 == 0:
            return 1
        return 0
    if slope2 == "未定義":
        if slope1 == 0:
            return 1
        return 0
    if slope1 * slope2 == -1:
        return 1
    return 0


if __name__ == '__main__':
    Q = int(input())

    for i in range(Q):
        all_list = list(map(int, input().split()))
        p0_list = all_list[:2]
        p1_list = all_list[2:4]
        p2_list = all_list[4:6]
        p3_list = all_list[6:]

        if is_parallel(p0_list, p1_list, p2_list, p3_list):
            print("2")
        elif is_orthogonal(p0_list, p1_list, p2_list, p3_list):
            print("1")
        else:
            print("0")

Submission status: Wrong Answer

Solution code:
# coding=utf-8


def cross_product(vect1, vect2):
    return vect1[0]*vect2[1] - vect1[1]*vect2[0]


def vector_minus(vect1, vect2):
    return [el1 - el2 for el1, el2 in zip(vect1, vect2)]


def line_slope(line_from, line_to):
    try:
        slope = (line_to[1] - line_from[1])/(line_to[0] - line_from[0])
    except ZeroDivisionError:
        slope = "未定義"
    return slope


"""
def is_parallel(l_from1, l_to1, l_from2, l_to2):
    slope1 = line_slope(l_from1, l_to1)
    slope2 = line_slope(l_from2, l_to2)
    if slope1 == slope2:
        return 1
    return 0
"""


def is_parallel(l_from1, l_to1, l_from2, l_to2):
    line1 = vector_minus(l_to1, l_from1)
    line2 = vector_minus(l_to2, l_from2)
    if cross_product(line1, line2) == 0:
        return 1
    return 0


def is_orthogonal(l_from1, l_to1, l_from2, l_to2):
    slope1 = line_slope(l_from1, l_to1)
    slope2 = line_slope(l_from2, l_to2)
    if slope1 == "未定義":
        if slope2 == 0:
            return 1
        return 0
    if slope2 == "未定義":
        if slope1 == 0:
            return 1
        return 0
    if slope1 * slope2 == -1:
        return 1
    return 0


if __name__ == '__main__':
    Q = int(input())

    for i in range(Q):
        all_list = list(map(int, input().split()))
        p0_list = all_list[:2]
        p1_list = all_list[2:4]
        p2_list = all_list[4:6]
        p3_list = all_list[6:]

        if is_parallel(p0_list, p1_list, p2_list, p3_list):
            print("2")
        elif is_orthogonal(p0_list, p1_list, p2_list, p3_list):
            print("1")
        else:
            print("0")

Submission status: Accepted

Solution code:
#内積0の場合直行している
#外積0の場合平行
def main():
  q = int(input())
  for i in range(q):
    print(parallel_orthogonal())

def parallel_orthogonal():
  xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
  l1_start = complex(xp0, yp0)
  l1_end = complex(xp1, yp1)
  l2_start = complex(xp2, yp2)
  l2_end = complex(xp3, yp3)

  if 0 == dot(l1_end - l1_start, l2_end - l2_start):
    return 1
  if 0 == cross(l1_end - l1_start, l2_end - l2_start):
    return 2
  return 0

# p0..p3がそれぞれ座標になっている

#内積
def dot(a, b):
  return a.real * b.real + a.imag * b.imag

#外積
def cross(a, b):
  return a.real * b.imag - a.imag * b.real

main()

Submission status: Accepted

Solution code:
from sys import stdin
readline = stdin.readline


def main():
    q = int(readline())
    for i in range(q):
        print(parallel_orthogonal())


def parallel_orthogonal():
    xy = map(int, readline().split())
    p0, p1, p2, p3 = [x + y * 1j for x, y in zip(*[xy] * 2)]
    if 0 == dot(p1 - p0, p3 - p2):
        return 1
    if 0 == cross(p1 - p0, p3 - p2):
        return 2
    return 0


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def cross(a, b):
    return a.real * b.imag - a.imag * b.real
main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
q = int(raw_input())
for i in range(q):
    l = map(float,raw_input().split())
    if l[2] - l[0] == 0:
        if l[6] - l[4] == 0:
            print 2
        elif l[7]-l[5] == 0:
            print 1
        else:
            print 0
    elif l[6] - l[4] == 0:
        if l[2] - l[0] == 0:
            print 2
        elif l[3] - l[1] == 0:
            print 1
        else:
            print 0
    else:
        s1 = (l[3] - l[1], l[2] - l[0])
        s2 = (l[7] - l[5], l[6] - l[4])
        if s1[0]/s1[1] == s2[0]/s2[1]:
            print 2
        elif s1[0]*s2[0] + s1[1]*s2[1] == 0:
            print 1
        else:
            print 0

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

q = int(raw_input())
for i in range(q):
    xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(float,raw_input().split())
    if xp1 - xp0 == 0:
        if xp3 - xp2 == 0:
            print 2
        elif yp3 - yp2 == 0:
            print 1
        else:
            print 0
    elif xp3 - xp2 == 0:
        if xp1 - xp0 == 0:
            print 2
        elif yp1 - yp0 == 0:
            print 1
        else:
            print 0
    
    else:
        s1 = (yp1 - yp0, xp1 - xp0)
        s2 = (yp3 - yp2, xp3 - xp2)
        if s1[0]/s1[1] == s2[0]/s2[1]:
            print 2
        elif s1[0]*s2[0] + s1[1]*s2[1] == 0:
            print 1
        else:
            print 0

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

q = int(raw_input())
for i in xrange(q):
    xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(float,raw_input().split())
    if xp1 - xp0 == 0:
        if xp3 - xp2 == 0:
            print 2
        elif yp3 - yp2 == 0:
            print 1
        else:
            print 0
    elif xp3 - xp2 == 0:
        if xp1 - xp0 == 0:
            print 2
        elif yp1 - yp0 == 0:
            print 1
        else:
            print 0
    
    else:
        s1 = (yp1 - yp0, xp1 - xp0)
        s2 = (yp3 - yp2, xp3 - xp2)
        if s1[0]/s1[1] == s2[0]/s2[1]:
            print 2
        elif s1[0]*s2[0] + s1[1]*s2[1] == 0:
            print 1
        else:
            print 0

Submission status: Accepted

Solution code:
from itertools import starmap

q = int(input())
while q:
    q -= 1
    p0, p1, p2, p3 = starmap(complex, zip(*[map(int, input().split())] * 2))
    prod = (p1 - p0).conjugate() * (p3 - p2)
    print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)

Submission status: Accepted

Solution code:
for t in xrange(input()):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, raw_input().split())
    dx0 = x1 - x0
    dy0 = y1 - y0
    dx1 = x3 - x2
    dy1 = y3 - y2
    ov = dx0*dy1 - dy0*dx1
    iv = dx0*dx1 + dy0*dy1
    if iv == 0:
        print 1
    elif ov == 0:
        print 2
    else:
        print 0

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import enum


EPS = 1e-10


class LinesRelation(enum.Enum):
    other = 0
    orthogonal = 1
    parallel = 2


def inner_product(v1, v2):
    return v1.real * v2.real + v1.imag * v2.imag


def outer_product(v1, v2):
    return v1.real * v2.imag - v1.imag * v2.real


def judge_lines_relation(l1_start, l1_end, l2_start, l2_end):
    v1 = l1_end - l1_start
    v2 = l2_end - l2_start
    if abs(outer_product(v1, v2)) < EPS:
        return LinesRelation.parallel
    elif abs(inner_product(v1, v2)) < EPS:
        return LinesRelation.orthogonal
    else:
        return LinesRelation.other


def main():
    q = int(input())
    for _ in range(q):
        xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
        l1_start = complex(xp0, yp0)
        l1_end = complex(xp1, yp1)
        l2_start = complex(xp2, yp2)
        l2_end = complex(xp3, yp3)
        print(judge_lines_relation(l1_start, l1_end, l2_start, l2_end).value)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
q = int(raw_input())
for _ in xrange(q):
  x0,y0,x1,y1,x2,y2,x3,y3 = map(float, raw_input().split())
  ax = x1-x0
  ay = y1-y0
  bx = x3-x2
  by = y3-y2
  inner = ax*bx+ay*by
  outer = ax*by-ay*bx
  if inner == 0:
    print 1
  elif outer == 0:
    print 2
  else:
    print 0

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2

output:
2
1
0
"""

import sys


def get_line(line_info):
    for line_pair in line_info:
        line_axis = tuple(map(int, line_pair))
        p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        # print(p0, p1, p2, p3)
        if dot(p1 - p0, p3 - p2) == 0:
            print('1')
        elif cross(p1 - p0, p3 - p2) == 0:
            print('2')
        else:
            print('0')
    return line_info


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    questions = int(_input[0])
    lines = map(lambda x: x.split(), _input[1:])
    ans = get_line(lines)

Submission status: Accepted

Solution code:
import sys
 
 
def get_line(line_info):
    for line_pair in line_info:
        line_axis = tuple(map(int, line_pair))
        p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        # print(p0, p1, p2, p3)
        if dot(p1 - p0, p3 - p2) == 0:
            print('1')
        elif cross(p1 - p0, p3 - p2) == 0:
            print('2')
        else:
            print('0')
    return line_info
 
 
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
 
 
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
 
 
if __name__ == '__main__':
    _input = sys.stdin.readlines()
    questions = int(_input[0])
    lines = map(lambda x: x.split(), _input[1:])
    ans = get_line(lines)

Submission status: Accepted

Solution code:
for _ in [0]*int(input()):
    a,b,c,d,e,f,g,h=map(int,input().split())
    print(1 if (c-a)*(g-e)==-(d-b)*(h-f) else(2 if (c-a)*(h-f)==(d-b)*(g-e) else 0))

Submission status: Accepted

Solution code:
# Vector class
class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def is_orthogonal(self, v):
        if self.x * v.x + self.y * v.y == 0:
            return True
        else:
            return False
    def is_parallel(self, v):
        if self.x * v.y - self.y * v.x == 0:
            return True
        else:
            return False

# Acceptance of input and judge

import sys

file_input = sys.stdin

q = map(int, file_input.readline().split())

for line in file_input:
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(int, line.split())
    s1 = Vector(x_p1 - x_p0, y_p1 - y_p0)
    s2 = Vector(x_p3 - x_p2, y_p3 - y_p2)
    if s1.is_parallel(s2):
        print(2)
    elif s1.is_orthogonal(s2):
        print(1)
    else:
        print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import pprint

#fd = os.open('CGL_2_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())

def judge(lst):
    x0, y0, x1, y1, x2, y2, x3, y3 = lst
    v0 = (x1 - x0, y1 - y0)
    v1 = (x3 - x2, y3 - y2)

    dot = v0[0] * v1[0] + v0[1] * v1[1]
    cross = v0[0] * v1[1] - v0[1] * v1[0]

    if dot == 0:
        print(1)
    elif cross == 0:
        print(2)
    else:
        print(0)


N = int(input())
for i in range(N):
    lst = list(map(int, input().split()))
    judge(lst)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
n = int(readline())
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
for _ in [0] * n:
    line_axis = tuple(map(int, readline().split()))
    p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
    if dot(p1 - p0, p3 - p2) == 0:
        print('1')
    elif cross(p1 - p0, p3 - p2) == 0:
        print('2')
    else:
        print('0')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
n = int(readline())
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
for _ in [0] * n:
    line_axis = tuple(map(int, readline().split()))
    p0, p1, p2, p3 = (complex(x, y) for x, y in zip(line_axis[::2], line_axis[1::2]))
    if dot(p1 - p0, p3 - p2) == 0:
        print('1')
    elif cross(p1 - p0, p3 - p2) == 0:
        print('2')
    else:
        print('0')

Submission status: Accepted

Solution code:
from itertools import starmap
import sys
readline = sys.stdin.readline
q = int(readline())
while q:
    q -= 1
    p0, p1, p2, p3 = starmap(complex, zip(*[map(int, readline().split())] * 2))
    prod = (p1 - p0).conjugate() * (p3 - p2)
    print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)

Submission status: Accepted

Solution code:
from itertools import starmap
import sys
readline = sys.stdin.readline
q = int(readline())
for _ in [0] * q:
    p0, p1, p2, p3 = starmap(complex, zip(*[map(int, readline().split())] * 2))
    prod = (p1 - p0).conjugate() * (p3 - p2)
    print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)

Submission status: Accepted

Solution code:
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]

q = int(input())
for i in range(q):
    x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
    a = [x1-x0,y1-y0]
    b = [x3-x2,y3-y2]
    if dot(a,b) == 0 : print(1)
    elif cross(a,b) == 0 : print(2)
    else : print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


class Point(object):
    epsilon = 1e-10

    def __init__(self, x=0.0, y=0.0):
        if isinstance(x, tuple):
            self.x = x[0]
            self.y = x[1]
        else:
            self.x = x
            self.y = y

    # ????????????
    def __add__(self, other):
        return (self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return (self.x - other.x, self.y - other.y)

    def __mul__(self, other):
        return (other * self.x, other * self.y)

    def __truediv__(self, other):
        return (other / self.x, other / self.y)

    def __lt__(self, other):
        if self.x == other.x:
            return self.y < other.y
        else:
            return self.x < other.x

    def __eq__(self, other):
        from math import fabs
        if fabs(self.x - other.x) < Point.epsilon and fabs(self.y - other.y) < Point.epsilon:
            return True
        else:
            return False

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        from math import sqrt
        return sqrt(self.norm())


class Vector(Point):
    @classmethod
    def dot(cls, a, b):
        return a.x * b.x + a.y * b.y

    @classmethod
    def cross(cls, a, b):
        return a.x * b.y - a.y * b.x

    @classmethod
    def is_orthogonal(cls, a, b):
        return Vector.dot(a, b) == 0.0

    @classmethod
    def is_parallel(cls, a, b):
        return Vector.cross(a, b) == 0.0


class Segment(object):
    def __init__(self, p1=Point(), p2=Point()):
        if isinstance(p1, Point):
            self.p1 = p1
            self.p2 = p2
        elif isinstance(p1, tuple):
            self.p1 = Point(p1[0], p1[1])
            self.p2 = Point(p2[0], p2[1])

    @classmethod
    def is_orthogonal(cls, s1, s2):
        a = Vector(s1.p2 - s1.p1)
        b = Vector(s2.p2 - s2.p1)
        return Vector.is_orthogonal(a, b)

    @classmethod
    def is_parallel(cls, s1, s2):
        a = Vector(s1.p2 - s1.p1)
        b = Vector(s2.p2 - s2.p1)
        return Vector.is_parallel(a, b)


class Line(Segment):
    pass


class Cirle(object):
    def __init__(self, c=Point(), r=0.0):
        self.c = c
        self.r = r


def solve(data):
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = data
    a = Segment((x_p0, y_p0), (x_p1, y_p1))
    b = Segment((x_p2, y_p2), (x_p3, y_p3))
    if Segment.is_orthogonal(a, b):
        return 1
    elif Segment.is_parallel(a, b):
        return 2
    else:
        return 0


def main(args):
    q = int(input())
    for _ in range(q):
        result = solve([int(x) for x in input().split()])
        print(result)

if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n = int(input())

def dot(a,b):
    return a[0] * b[0] + a[1] * b[1]

from math import sqrt
def s(a):
    return a[0]**2 + a[1]**2
for i in range(n):
    points = [int(j) for j in input().split()]
    p0 = points[:2]
    p1 = points[2:4]
    a = [p0[0]-p1[0],p0[1]-p1[1]]
    p2 = points[4:6]
    p3 = points[6:8]
    b = [p2[0]-p3[0],p2[1]-p3[1]]
    c = dot(a,b)**2/(s(a) * s(b))
    if c == 0:
        print(1)
    elif c == 1:
        print(2)
    else:
        print(0)

Submission status: Accepted

Solution code:
n = int(input())

def dot(a,b):
    return a[0] * b[0] + a[1] * b[1]
def s(a):
    return a[0]**2 + a[1]**2

for i in range(n):
    points = [int(j) for j in input().split()]
    p0 = points[:2]
    p1 = points[2:4]
    p2 = points[4:6]
    p3 = points[6:8]
    a = [p0[0]-p1[0],p0[1]-p1[1]]
    b = [p2[0]-p3[0],p2[1]-p3[1]]
    c = dot(a,b)**2/(s(a) * s(b))
    if c == 0: print(1)
    elif c == 1: print(2)
    else: print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import collections
import math


class Vector2(collections.namedtuple("Vector2", ["x",  "y"])):

    def __add__(self, other):
        return Vector2(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector2(self.x - other.x, self.y - other.y)

    def __neg__(self):
        return Vector2(-self.x, -self.y)

    def __pos__(self):
        return Vector2(+self.x, +self.y)

    def __abs__(self):  # norm
        return math.sqrt(float(self.x * self.x + self.y * self.y))

    def dot(self, other):  # dot product
        return self.x * other.x + self.y * other.y

    def cross(self, other):  # cross product
        return self.x * other.y - self.y * other.x


if __name__ == '__main__':

    n = int(input())
    
    for _ in range(n):
        l = list(map(int, input().split()))
        s1 = Vector2(l[2], l[3]) - Vector2(l[0], l[1])
        s2 = Vector2(l[6], l[7]) - Vector2(l[4], l[5])

        if abs(s1.dot(s2)) == 0:
            print(1)
        elif abs(s1.cross(s2)) == 0:
            print(2)
        else:
            print(0)

Submission status: Accepted

Solution code:
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

class Line():
    def __init__(self, x1, y1, x2, y2):
        self.p1 = Point(x1, y1)
        self.p2 = Point(x2, y2)

    def get_slope(self):
        if self.p1.x == self.p2.x:
            return float('inf')
        return (self.p2.y - self.p1.y)/(self.p2.x - self.p1.x)

q = int(input())
for i in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split(' ')))
    line1, line2 = Line(x0, y0, x1, y1), Line(x2, y2, x3, y3)
    a1, a2 = line1.get_slope(), line2.get_slope()
    if a1 == a2: # 平行
        print('2')
    elif round(a1*a2, 8) == -1.0:
        print('1')
    elif (a1 == float('inf') and a2 == 0) or (a1 == 0 and a2 == float('inf')):
        print('1')
    else:
        print('0')

Submission status: Accepted

Solution code:
# coding=utf-8


def vector_product(vect1, vect2):
    return [el1 * el2 for el1, el2 in zip(vect1, vect2)]


def inner_product(vect1, vect2):
    return sum(vector_product(vect1, vect2))


def cross_product(vect1, vect2):
    return vect1[0]*vect2[1] - vect1[1]*vect2[0]


def vector_minus(vect1, vect2):
    return [el1 - el2 for el1, el2 in zip(vect1, vect2)]


def line_slope(line_from, line_to):
    try:
        slope = (line_to[1] - line_from[1])/(line_to[0] - line_from[0])
    except ZeroDivisionError:
        slope = "未定義"
    return slope


"""
def is_parallel(l_from1, l_to1, l_from2, l_to2):
    slope1 = line_slope(l_from1, l_to1)
    slope2 = line_slope(l_from2, l_to2)
    if slope1 == slope2:
        return 1
    return 0
"""


def is_parallel(l_from1, l_to1, l_from2, l_to2):
    line1 = vector_minus(l_to1, l_from1)
    line2 = vector_minus(l_to2, l_from2)
    if cross_product(line1, line2) == 0:
        return 1
    return 0


def is_orthogonal(l_from1, l_to1, l_from2, l_to2):
    line1 = vector_minus(l_to1, l_from1)
    line2 = vector_minus(l_to2, l_from2)
    if inner_product(line1, line2) == 0:
        return 1
    return 0


if __name__ == '__main__':
    Q = int(input())

    for i in range(Q):
        all_list = list(map(int, input().split()))
        p0_list = all_list[:2]
        p1_list = all_list[2:4]
        p2_list = all_list[4:6]
        p3_list = all_list[6:]

        if is_parallel(p0_list, p1_list, p2_list, p3_list):
            print("2")
        elif is_orthogonal(p0_list, p1_list, p2_list, p3_list):
            print("1")
        else:
            print("0")