Problem:


Reflection

For given three points p1, p2, p, find the reflection point x of p onto p1p2.

Input

xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq&minus;1 ypq&minus;1

In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.

Output

xt0 yt0
xt1 yt1
...
xtq-1 ytq-1

-->

For each query, print the coordinate of the reflection point x. The output values should be in a decimal fraction with an error less than 0.00000001.

Constraints

1 ≤ q ≤ 1000

-10000 ≤ xi, yi ≤ 10000

p1 and p2 are not identical.

Sample Input 1

0 0 2 0
3
-1 1
0 1
1 1

Sample Output 1

-1.0000000000 -1.0000000000
0.0000000000 -1.0000000000
1.0000000000 -1.0000000000

Sample Input 2

0 0 3 4
3
2 5
1 4
0 3

Sample Output 2

4.2400000000 3.3200000000
3.5600000000 2.0800000000
2.8800000000 0.8400000000



Sample input:
0 0 2 0
3
-1 1
0 1
1 1


Sample output:
-1.0000000000 -1.0000000000
0.0000000000 -1.0000000000
1.0000000000 -1.0000000000

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(float,input().split())
a = complex(a,b)
b = complex(c,d)
q=int(input())
for i in range(q):
  x,y=map(int,input().split())
  c=complex(x,y)
  q = b-a
  c -= a
  p = a+q*(c/q).conjugate()
  print("{:.10} {:.10}".format(p.real, p.imag))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(float,input().split())
a = complex(a,b)
b = complex(c,d)
n=int(input())
for i in range(n):
  x,y=map(int,input().split())
  c=complex(x,y)
  q = b-a
  c -= a
  p = a+q*(c/q).conjugate()
  print("{:.10} {:.10}".format(p.real, p.imag))

Submission status: Wrong Answer

Solution code:
a, b,c,d = map(float,input().split())
a = complex(a,b)
b = complex(c,d)

for _ in [0] *int(input()):
  c = complex(*map(float, input().split()))
  q = b-a
  c -= a
  p = a+q*(c/q).conjugate()
  print("{:.10} {:.10}".format(p.real, p.imag))

Submission status: Wrong Answer

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

def projection(s,p):
  base=b-a
  r=dot(p-a,base)/(abs(base)**2)
  return a+base*r

def reflect(s,p):
  return p+(projection(s,p)-p)*2

x0,y0,x1,y1 = map(float,input().split())
a = complex(x0,y0)
b = complex(x1,y1)
n=int(input())

for i in range(n):
  x,y=map(int,input().split())
  c=complex(x,y)
  p=reflect(a,c)
  print("{:.10} {:.10}".format(p.real, p.imag))

Submission status: Wrong Answer

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

def projection(s,p):
  base=abs(b-a)
  r=dot(p-a,base)/(base**2)
  return a+base*r

def reflect(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    v = projection(a, b)
    u = v - b
    p3 = p2 + 2 * u
    return p3

x0,y0,x1,y1 = map(float,input().split())
a = complex(x0,y0)
b = complex(x1,y1)
n=int(input())

for i in range(n):
  x,y=map(int,input().split())
  c=complex(x,y)
  p=reflect(a,b,c)
  print("{:.10} {:.10}".format(p.real, p.imag))

Submission status: Wrong Answer

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

def projection(a,b):
  return a* dot(a,b)/(abs(a)**2)

def reflect(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    v = projection(a, b)
    u = v - b
    p3 = p2 + 2 * u
    return p3

x0,y0,x1,y1 = map(float,input().split())
a = complex(x0,y0)
b = complex(x1,y1)
n=int(input())

for i in range(n):
  x,y=map(int,input().split())
  c=complex(x,y)
  p=reflect(a,b,c)
  print("{:.10} {:.10}".format(p.real, p.imag))

Submission status: Wrong Answer

Solution code:
import sys
from itertools import starmap
readline = sys.stdin.readline
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
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
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
s = Segment(*starmap(complex, zip(*[map(int, readline().split())] * 2)))
n = int(readline())
for _ in [0] * n:
    p1 = reflect(s, complex(*map(float, readline().split())))
    print(p1.real, p1.imag)

Submission status: Wrong Answer

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 __mul__(self, scalar):  # cross product
        return Vector2(self.x * scalar, self.y * scalar)

    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__':

    a, b, c, d = map(int, input().split())
    p1 = Vector2(a, b)
    p2 = Vector2(c, d)
    base = p2 - p1
    q = int(input())

    for _ in range(q):
        e, f = map(int, input().split())
        hypo = Vector2(e - a, f - b)
        p_ = p1 + base * (hypo.dot(base) / abs(base)**2)
        x = p_ + (p_ - hypo) * 2
        print(x.x, x.y)

Submission status: Wrong Answer

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 __mul__(self, scalar):  # cross product
        return Vector2(self.x * scalar, self.y * scalar)

    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__':

    a, b, c, d = map(int, input().split())
    p1 = Vector2(a, b)
    p2 = Vector2(c, d)
    base = p2 - p1
    q = int(input())
    ans = []
    for _ in range(q):
        e, f = map(int, input().split())
        hypo = Vector2(e - a, f - b)
        p_ = p1 + base * (hypo.dot(base) / abs(base)**2)
        x = hypo + (p_ - hypo) * 2
        ans.append(x)

    for x in ans:
        print(x.x, x.y)

Submission status: Wrong Answer

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 __mul__(self, scalar):  # cross product
        return Vector2(self.x * scalar, self.y * scalar)

    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__':

    a, b, c, d = map(int, input().split())
    p1 = Vector2(a, b)
    p2 = Vector2(c, d)
    base = p2 - p1
    q = int(input())
    ans = []
    for _ in range(q):
        e, f = map(int, input().split())
        hypo = Vector2(e - a, f - b)
        p_ = p1 + base * (hypo.dot(base) / float(base.x**2 + base.y**2))
        x = hypo + (p_ - hypo) * 2
        ans.append(x)

    for x in ans:
        print(x.x, x.y)

Submission status: Wrong Answer

Solution code:
import math

class Point():
    def __init__(self, x=None, y=None):
        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 projection(self, p):
        a = (self.p2.y - self.p1.y)/(self.p2.x - self.p1.x) if self.p2.x != self.p1.x else float('inf')
        b = self.p2.y - a*self.p2.x
        d = abs(-1*a*p.x + p.y - b)/math.sqrt(1 + a*a)
        ans_y = [p.y + math.sqrt(4*d*d/(a*a+1)), p.y - math.sqrt(4*d*d/(a*a+1))]
        ans_x = [p.x - a*(_y - p.y) for _y in ans_y]

        rst_x, rst_y = None, None
        tmp = abs(-1*a*ans_x[0] + ans_y[0] - b)/math.sqrt(1 + a*a) - d
        if tmp < abs(-1*a*ans_x[1] + ans_y[1] - b)/math.sqrt(1 + a*a) - d:
            rst_x, rst_y = ans_x[0], ans_y[0]
        else:
            rst_x, rst_y = ans_x[1], ans_y[1]
        return round(rst_x, 9), round(rst_y, 9)

x1, y1, x2, y2 = list(map(int, input().split(' ')))
line = Line(x1, y1, x2, y2)
q = int(input())
for i in range(q):
    x, y = list(map(int, input().split(' ')))
    p = Point(x, y)
    rst_x, rst_y = line.projection(p)
    print(rst_x, rst_y)

Submission status: Wrong Answer

Solution code:
# coding=utf-8
from math import sqrt


def inner_product(vect1, vect2):
    return sum([(v1_el*v2_el) for v1_el, v2_el in zip(vect1, vect2)])


def vector_abs(vect):
    return sqrt(sum([element**2 for element in vect]))


def direction_unit_vector(p_from, p_to):
    d_vector = [(xt - xf) for xt, xf in zip(p_to, p_from)]
    d_u_vector = [element/vector_abs(d_vector) for element in d_vector]
    return d_u_vector


def projection(origin, line_from, line_to):
    direction_unit = direction_unit_vector(line_from, line_to)
    origin_d_vector = [(org-lf) for org, lf in zip(origin, line_from)]
    inject_dist = inner_product(direction_unit, origin_d_vector)
    on_line_vect = [inject_dist*element for element in direction_unit]
    return [olv_el + lf_el for olv_el, lf_el in zip(on_line_vect, line_from)]


def reflection(origin, line_from, line_to):
    mid_point = projection(origin, line_from, line_to)
    direction = [2*(mp_el - or_el) for mp_el, or_el in zip(mid_point, origin)]
    reflected = [(dr_el + or_el) for dr_el, or_el in zip(direction, origin)]
    return reflected


if __name__ == '__main__':
    xy_list = list(map(int, input().split()))
    p1_list = xy_list[:2]
    p2_list = xy_list[2:]
    Q = int(input())

    for i in range(Q):
        p_list = list(map(int, input().split()))
        x_list = reflection(p_list, p1_list, p2_list)
        print(' '.join(map(str, x_list)))

Submission status: Accepted

Solution code:
x1,y1,x2,y2=map(float,raw_input().split(" "))
for i in xrange(int(raw_input())):
    px,py=map(float,raw_input().split(" "))
    dxa=(x2-x1)
    dya=(y2-y1)
    da=dxa**2+dya**2
    dxb=(px-x1)
    dyb=(py-y1)
    ip=dxb*dxa+dya*dyb
    r=ip/da
    kouten_x=x1+r*dxa
    kouten_y=y1+r*dya
    ref_x=px+2.0*(kouten_x-px)
    ref_y=py+2.0*(kouten_y-py)
    print "{0:.10f} {1:.10f}".format(ref_x,ref_y)

Submission status: Accepted

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

def main():
    x1, y1, x2, y2 = map(int, readline().split())
    p1, p2 = x1 + y1 * 1j, x2 + y2 * 1j
    q = int(readline())
    for i in range(q):
        xi, yi = map(int, readline().split())
        pi = xi + yi * 1j
        cross = p1 + (p2 - p1) * projecter(p2 - p1, pi - p1)
        cross = cross * 2 - pi
        print('{:.10f} {:.10f}'.format(cross.real, cross.imag))


def projecter(a, b):
    return dot(a, b) / dot(a, a)


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

Submission status: Accepted

Solution code:
# coding: utf-8
xp0,yp0,xp1,yp1 = map(float,raw_input().split())
q = int(raw_input())
for i in range(q):
    xp2,yp2 = map(float,raw_input().split())
    p0p2 = (xp2-xp0,yp2-yp0)
    p0p1 = (xp1-xp0,yp1-yp0)
    k = ((p0p2[0]*p0p1[0]+p0p2[1]*p0p1[1])/(p0p1[0]**2 + p0p1[1]**2))
    # p2t??¨p0p1????????????T??¨??????
    p0T = (k*p0p1[0],k*p0p1[1])
    OT = (xp0+p0T[0],yp0+p0T[1])
    p2t = (2*(OT[0]-xp2),2*(OT[1]-yp2))
    Ot =  (p2t[0] + xp2,p2t[1] + yp2)
    print "%.10f %.10f" % (Ot[0],Ot[1])

Submission status: Accepted

Solution code:
# coding: utf-8
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

init_point = map(float,raw_input().split())
p0 = Point(init_point[0], init_point[1])
p1 = Point(init_point[2], init_point[3])

q = int(raw_input())
for i in range(q):
    xp2,yp2 = map(float,raw_input().split())
    p2 = Point(xp2,yp2)
    p0p2 = Point(p2.x - p0.x, p2.y - p0.y)
    p0p1 = Point(p1.x - p0.x, p1.y - p0.y)
    k = ((p0p2.x * p0p1.x + p0p2.y * p0p1.y)/(p0p1.x ** 2 + p0p1.y ** 2))
    # p2t??¨p0p1????????????T??¨??????
    p0T = Point(k * p0p1.x, k * p0p1.y)
    OT = Point(p0.x + p0T.x, p0.y + p0T.y)
    p2t = Point(2*(OT.x - p2.x), 2*(OT.y - p2.y))
    Ot =  Point(p2t.x + xp2, p2t.y + p2.y)
    print "%.10f %.10f" % (Ot.x, Ot.y)

Submission status: Accepted

Solution code:
x1, y1, x2, y2 = map(int, input().split())
q = int(input())

p1, p2 = complex(x1, y1), complex(x2, y2)
p1p2 = p2 - p1
d2_p1p2 = p1p2.real ** 2 + p1p2.imag ** 2

while q:
    q -= 1
    p0 = complex(*map(int, input().split()))
    p1p0 = p0 - p1
    t = (p1p2.real * p1p0.real + p1p2.imag * p1p0.imag) / d2_p1p2
    ref = p0 + 2 * (p1p2 * t - p1p0)
    print(ref.real, ref.imag)

Submission status: Accepted

Solution code:
x0,y0,x1,y1 = map(float,input().split())
n = int(input())
vx1,vy1 = x1-x0,y1-y0

for i in range(n):
    x2,y2 = map(float,input().split())
    vx2,vy2 = x2-x0,y2-y0
    sqr = vx1**2 + vy1**2
    in_p = vx1*vx2 + vy1*vy2
    xt,yt = 2*in_p*vx1/sqr + 2*x0-x2,2*in_p*vy1/sqr + 2*y0-y2
    print("{0:.10f} {1:.10f}".format(xt,yt))

Submission status: Accepted

Solution code:
from math import sqrt
x1, y1, x2, y2 = map(int, raw_input().split())
dx = x2 - x1
dy = y2 - y1
for i in xrange(input()):
    x, y = map(int, raw_input().split())
    a = float(dx*(x - x1) + dy*(y - y1)) / (dx**2 + dy**2)
    print "%.09f %0.09f" % (2*x1 - x + 2*a*dx, 2*y1 - y + 2*a*dy)

Submission status: Accepted

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

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


# ????????????b???????????????a??????????????´????????£?°???±???????????????????????????
def project(a, b):
    return a * inner_product(a, b) / (abs(a) ** 2)


# p0??¨p1????????¶??´???????????????p2???????§°?§??????????
def reflect(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    v = project(a, b)
    u = v - b
    p3 = p2 + 2 * u
    return p3


def main():
    x_p0, y_p0, x_p1, y_p1 = map(float, input().split())
    p0 = complex(x_p0, y_p0)
    p1 = complex(x_p1, y_p1)
    q = int(input())
    for _ in range(q):
        p2 = complex(*map(float, input().split()))
        t = reflect(p0, p1, p2)
        print("{:.10f} {:.10f}".format(t.real, t.imag))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x1,y1,x2,y2 = map(float, raw_input().split())

q = int(raw_input())
for _ in xrange(q):
  x,y = map(float, raw_input().split())
  if x1 == x2:
    print "%f %f" % (x1*2-x, y)
  elif y1 == y2:
    print "%f %f" % (x, y1*2-y)
  else:
    a0 = (y2 - y1) / (x2 - x1)
    b0 = y1 - a0 * x1
    ap = -1 / a0
    bp = y - ap * x
    xe = (bp - b0) / (a0 - ap)
    ye = a0 * xe + b0
    xe = xe + (xe - x)
    ye = ye + (ye - y)
    print "%.12f %.12f" % (xe, ye)

Submission status: Accepted

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

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

output:
4.2400000000 3.3200000000
3.5600000000 2.0800000000
2.8800000000 0.8400000000
"""

import sys


def solve(_prj_info):
    for point in _prj_info:
        xp, yp = map(int, point)
        p = xp + yp * 1j
        hypo = p - p1
        prj = p1 + base * project(base, hypo)
        ref = p + (prj - p) * 2.0
        print('{0:.10f} {1:.10f}'.format(ref.real, ref.imag))

    return _prj_info


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


# abs(prj)/abs(base)
def project(a, b):
    return dot(a, b) / dot(a, a)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    base_info = _input[0].split()
    q_num = int(_input[1])
    prj_points = map(lambda x: x.split(), _input[2:])

    x1, y1, x2, y2 = map(int, base_info)
    p1, p2 = x1 + y1 * 1j, x2 + y2 * 1j
    base = p2 - p1
    res = solve(prj_points)

Submission status: Accepted

Solution code:
x1,y1,x2,y2 = map(float,input().split())
det = x1 - x2
if det != 0:
    a = (y1 - y2) / det
    b = (-(y1 * x2) + y2 * x1) / det

q = int(input())
x,y = [],[]
for i in range(q):
    x_t,y_t = map(float,input().split())
    x.append(x_t)
    y.append(y_t)

if det == 0:
    for i in range(q):
        print(-x[i],y[i])
elif y2 == y1:
    for i in range(q):
        print(x[i],-y[i])
else:
    for i in range(q):
        k = y[i] + 1/a * x[i]
        s = (k - b)/(a + 1/a)
        print(s+(s-x[i]),-1/a * (s+(s-x[i])) + k)

Submission status: Accepted

Solution code:
a,b,c,d=map(float,input().split())
a=complex(a,b)
b=complex(c,d)
for _ in [0]*int(input()):
    c=complex(*map(float,input().split()))
    q=b-a;c-=a
    p=a+q*(c/q).conjugate()
    print(p.real,p.imag)

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
    def dot_product(self, v):
        return self.x * v.x + self.y * v.y
    def quadrance(self):
        return self.x ** 2 + self. y ** 2
    def mul(self, k):
        return Vector(self.x * k, self.y *k)
    def __add__(self, v):
        return Vector(self.x + v.x, self.y + v.y)
    def __sub__(self, v):
        return Vector(self.x - v.x, self.y - v.y)
    def __str__(self):
        return "{0:.8f} {1:.8f}".format(self.x, self. y)
    def projection_on(self, v):
        return v.mul(self.dot_product(v) / v.quadrance())
    def rejection_from(self, v):
        return self - self.projection_on(v)

# Acceptance of input and Print the reflection point
import sys

file_input = sys.stdin

x_p1, y_p1, x_p2, y_p2 = map(int, file_input.readline().split())
p1_p2 = Vector(x_p2 - x_p1, y_p2 - y_p1)

q = int(file_input.readline())

for line in file_input:
    x_p, y_p = map(int, line.split())
    p1_p = Vector(x_p - x_p1, y_p - y_p1)
    r_v = p1_p.rejection_from(p1_p2)
    o_p = Vector(x_p, y_p)
    print(o_p - r_v.mul(2))

Submission status: Accepted

Solution code:
import sys
from itertools import starmap
readline = sys.stdin.readline
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
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
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
s = Segment(*starmap(complex, zip(*[map(int, readline().split())] * 2)))
n = int(readline())
for _ in [0] * n:
    p1 = reflect(s, complex(*map(float, readline().split())))
    print("{0:.10f} {1:.10f}".format(p1.real, p1.imag))

Submission status: Accepted

Solution code:
import sys
from itertools import starmap
readline = sys.stdin.readline
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
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
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
s = Segment(*starmap(complex, zip(*[map(float, readline().split())] * 2)))
n = int(readline())
for _ in [0] * n:
    p1 = reflect(s, complex(*map(float, readline().split())))
    print("{0:.10f} {1:.10f}".format(p1.real, p1.imag))

Submission status: Accepted

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

x1,y1,x2,y2 = [int(i) for i in input().split()] 
q = int(input())
for i in range(q):
    x,y = [int(i) for i in input().split()]
    a = [x2-x1,y2-y1]
    b = [x-x1,y-y1]
    co = dot(a,b) / dot(a,a)
    isec = [co*a[0]+x1,co*a[1]+y1]
    c = [isec[0] - x, isec[1] - y]
    print(isec[0]+c[0],isec[1]+c[1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B&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 Point(self.x + other.x, self.y + other.y)

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

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

    def __truediv__(self, other):
        return Point(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):
    def __init__(self, x=0.0, y=0.0):
        if isinstance(x, tuple):
            self.x = x[0]
            self.y = x[1]
        elif isinstance(x, Point):
            self.x = x.x
            self.y = x.y
        else:
            self.x = x
            self.y = y

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

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

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

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

    @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 project(s, p):
    base = Vector(s.p2 - s.p1)
    a = Vector(p - s.p1)
    r = Vector.dot(a, base)
    r /= base.norm()
    return s.p1 + base * r


def reflect(s, p):
    proj = project(s, p)
    return p + (proj - p)*2


def main(args):
    x_p1, y_p1, x_p2, y_p2 = map(int, input().split())
    q = int(input())
    s = Segment((x_p1, y_p1), (x_p2, y_p2))
    for _ in range(q):
        x, y = map(int, input().split())
        p = Point(x, y)
        result = reflect(s, p)
        print('{:.10f} {:.10f}'.format(result.x, result.y))


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

Submission status: Accepted

Solution code:
xp1, yp1, xp2, yp2 = map(int, input().split())
q = int(input())

r = [xp2 - xp1, yp2 - yp1]

def a(p1,p2):
    s = (p1-xp1,p2-yp1)
    d = r[0] * s[0] + r[1] * s[1]
    a = xp1 + r[0] * d / (r[0]**2 + r[1]**2)
    b = yp1 + r[1] * d / (r[0]**2 + r[1]**2)
    return a,b

for i in range(q):
    x, y = map(int, input().split())
    x2,y2 = a(x, y)
    print(x + 2 * (x2 - x), y + 2 * (y2 - y))

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 __mul__(self, scalar):  # cross product
        return Vector2(self.x * scalar, self.y * scalar)

    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__':

    a, b, c, d = map(int, input().split())
    p1 = Vector2(a, b)
    p2 = Vector2(c, d)
    base = p2 - p1
    q = int(input())
    ans = []
    for _ in range(q):
        e, f = map(int, input().split())
        p = Vector2(e, f)
        hypo = Vector2(e - a, f - b)
        proj = p1 + base * (hypo.dot(base) / float(base.x**2 + base.y**2))
        x = p + (proj - p) * 2
        ans.append(x)

    for x in ans:
        print(x.x, x.y)

Submission status: Accepted

Solution code:
import math

class Point():
    def __init__(self, x=None, y=None):
        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 projection(self, p):
        a = (self.p2.y - self.p1.y)/(self.p2.x - self.p1.x) if self.p2.x != self.p1.x else float('inf')
        if a == 0:
            return (p.x, 2*self.p1.y - p.y)
        elif a == float('inf'):
            return (2*self.p1.x - p.x, p.y)
        else:
            b = self.p2.y - a*self.p2.x
            d = abs(-1*a*p.x + p.y - b)/math.sqrt(1 + a*a)
            ans_y = [p.y + math.sqrt(4*d*d/(a*a+1)), p.y - math.sqrt(4*d*d/(a*a+1))]
            ans_x = [p.x - a*(_y - p.y) for _y in ans_y]

            rst_x, rst_y = None, None
            tmp = abs(-1*a*ans_x[0] + ans_y[0] - b)/math.sqrt(1 + a*a) - d
            if tmp < abs(-1*a*ans_x[1] + ans_y[1] - b)/math.sqrt(1 + a*a) - d:
                rst_x, rst_y = ans_x[0], ans_y[0]
            else:
                rst_x, rst_y = ans_x[1], ans_y[1]
            return round(rst_x, 9), round(rst_y, 9)

x1, y1, x2, y2 = list(map(int, input().split(' ')))
line = Line(x1, y1, x2, y2)
q = int(input())
for i in range(q):
    x, y = list(map(int, input().split(' ')))
    p = Point(x, y)
    rst_x, rst_y = line.projection(p)
    print(rst_x, rst_y)