The light travels in a straight line and always goes in the minimal path between two points, are the basic laws of optics. 

Now, our problem is that, if a branch of light goes into a large and infinite mirror, of course,it will reflect, and leave away the mirror in another direction. Giving you the position of mirror and the two points the light goes in before and after the reflection, calculate the reflection point of the light on the mirror. 
   
You can assume the mirror is a straight line and the given two points can’t be on the different sizes of the mirror.

Input

The first line is the number of test case t(t<=100). 
   
The following every four lines are as follow: 
  X1 Y1 
  X2 Y2 
  Xs Ys 
  Xe Ye 

  (X1,Y1),(X2,Y2) mean the different points on the mirror, and (Xs,Ys) means the point the light travel in before the reflection, and (Xe,Ye) is the point the light go after the reflection. 

  The eight real number all are rounded to three digits after the decimal point, and the absolute values are no larger than 10000.0.

Output

  Each lines have two real number, rounded to three digits after the decimal point, representing the position of the reflection point.

Sample Input

1
0.000 0.000
4.000 0.000
1.000 1.000
3.000 1.000

Sample Output

2.000 0.000 

我记得这似乎是初中数学题目来着

求出对称点然后连起来 交点就是反射点

反正 直线交点 和对称点都是有模板的 直接套模板就行了

#include <bits/stdc++.h>
using namespace std;
#define INF 1e8
#define eps 1e-4
#define ll __int64
#define maxn 500010
#define mol 1000000007

struct point
{
    double x,y;
};
point symmetric_point(point p1, point l1, point l2)// 求p1的对称点
{
    point ret;
    if (l1.x > l2.x - eps && l1.x < l2.x + eps)//斜率不存在
    {
        ret.x = (2 * l1.x - p1.x);
        ret.y = p1.y;
    }
    else
    {
        double k = (l1.y - l2.y ) / (l1.x - l2.x);
        if(k + eps > 0 && k - eps < 0)//斜率为零
        {
            ret.x = p1.x;
            ret.y = l1.y - (p1.y - l1.y);
        }
        else
        {
            ret.x = (2*k*k*l1.x + 2*k*p1.y - 2*k*l1.y - k*k*p1.x + p1.x) / (1 + k*k);
            ret.y = p1.y - (ret.x - p1.x ) / k;
        }
    }
    return ret;
}
point intersection(point u1,point u2,point v1,point v2)//求两直线的交点
{
    point ret=u1;
    double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
    /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
    ret.x+=(u2.x-u1.x)*t;
    ret.y+=(u2.y-u1.y)*t;
    return ret;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        point m1,m2,l1,l2;
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&m1.x,&m1.y,&m2.x,&m2.y,&l1.x,&l1.y,&l2.x,&l2.y);
        point tmp=symmetric_point(l1,m1,m2);
        point ans=intersection(tmp,l2,m1,m2);
        printf("%.3lf %.3lf\n",ans.x,ans.y);
    }
    return 0;
}