Mirror and Light (点与直线)

Mirror and Light

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 821    Accepted Submission(s): 387

Problem Description

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 

Source

2009 Multi-University Training Contest 5 - Host by NUDT

直接套模板;

#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

struct Point
{
    double x,y;
    Point(double x = 0, double y = 0) : x(x),y(y) {};
    void input()
    {
        scanf("%lf %lf",&x,&y);
    }
} point[5];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        for(int i = 0; i < 4; i++)
            point[i].input();
        double a1 = point[1].y - point[0].y;
        double b1 = point[0].x - point[1].x;
        double c1 = point[0].y * point[1].x - point[0].x * point[1].y;
        double a2,b2,c2;
        double x,y,k;
        k = -2.0 * (a1 * point[2].x + b1 * point[2].y + c1) / (a1 * a1 + b1 * b1);
        x = point[2].x + k * a1;
        y = point[2].y + k * b1;
        a2 = point[3].y - y;
        b2 = x - point[3].x;
        c2 = y * point[3].x - point[3].y * x;
        double x1 = (c2 * b1 - c1 * b2) / (a1 * b2 - a2 * b1);
        double y1 = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
        if(b1 == 0) x1 = point[0].x;//其实不用考虑这两种情况也能AC,因为不考虑也不影响结果;
        if(a1 == 0) y1 = point[0].y;
        printf("%.3lf %.3lf\n",x1,y1);
    }
    return 0;
}
时间: 2024-11-05 16:38:27

Mirror and Light (点与直线)的相关文章

HDOJ 题目2857 Mirror and Light(关于直线对称点,直线交点)

Mirror and Light Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 1   Accepted Submission(s) : 1 Problem Description The light travels in a straight line and always goes in the minimal path betwee

HDU 2857 Mirror and Light

/* hdu 2857 Mirror and Light 计算几何 镜面反射 */ #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; const double DNF=100000001.0; int t; double x1,x2,y11,y2,xs,ys,xe,ye; struct Point { double x;

hdu 2857 点在直线上的投影+直线的交点

Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 814    Accepted Submission(s): 385 Problem Description The light travels in a straight line and always goes in the minimal path b

C#游戏开发快速入门 2.1 构建游戏场景

C#游戏开发快速入门 2.1  构建游戏场景 如果已经计划好了要编写什么样的游戏,在打开Unity以后,要做的第一件事情就是构建游戏场景(Scene).游戏场景就是玩家游戏时,在游戏视图中看到的一切,包括游戏背景.游戏角色.阳光等等,这些所有可视的元素在Unity中,被统称为游戏对象(GameObject).本节就先来学习游戏场景的构建. 2.1.1  新建游戏场景 就像是创建游戏就需要要新建游戏项目一样,构建游戏场景也是需要新建游戏场景的.只不过,Unity在开发者新建游戏项目的时候,已经默认

HDU-2857-Mirror and Light(计算几何)

Problem Description 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 ref

POJ1375 Intervals(直线与圆切线、线段合并)

题目链接: http://poj.org/problem?id=1375 题目描述: Intervals Description In the ceiling in the basement of a newly open developers building a light source has been installed. Unfortunately, the material used to cover the floor is very sensitive to light. It

poj1039——计算几何 求直线与线段交点,判断两条直线是否相交

poj1039——计算几何  求直线与线段交点,判断两条直线是否相交 Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9439   Accepted: 2854 Description The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipeline. During the de

【HDU 1687】Lucky Light(思维+计算几何)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1687 题意:有一个光源,下面有很多放置的板子,问光线被板子分割之后在地上能产生多少块亮区(看题中的图就能看懂). 分析:这个题的做法和省选第一天的C题很像,由于是求在地面上,也就是一条直线上的亮区,我们可以求出地面上被木板遮挡形成的暗区的左坐标和右坐标,然后合并区间就可以了.而求地面上的坐标,可以用相似三角形,若光源为(sx,sy),点为(x1,y1)和(x2,y2),则地面上的坐标为:sx-(sx-

Light Bulb

Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, t