当前位置: 代码迷 >> Ruby/Rails >> HDOJ 标题2857 Mirror and Light(关于直线对称点,直线交点)
  详细解决方案

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

热度:509   发布时间:2016-04-29 02:14:07.0
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 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
10.000 0.0004.000 0.0001.000 1.0003.000 1.000
 

Sample Output
2.000 0.000
 

Source
2009 Multi-University Training Contest 5 - Host by NUDT
 
ac代码
#include<stdio.h>#include<string.h>double xmi,ymi,xx,yy;void duichendian(double x1,double y1,double x2,double y2,double xs,double ys){	double k1,k2,b1,b2;	if(y2==y1)	{		xmi=xs;		ymi=2*y1-ys;	}	else	{		if(x2==x1)		{			xmi=2*x1-xs;			ymi=ys;		}		else		{			k1=(y2-y1)/(x2-x1);			k2=(x1-x2)/(y2-y1);			b1=y2-k1*x2;			b2=ys-k2*xs;			xmi=2*(b1-b2)/(k2-k1)-xs;			ymi=k2*(xmi-xs)+ys;		}	}}void jiaodian(double xs,double ys,double xe,double ye,double x1,double y1,double x2,double y2){	double k1,k2,b1,b2;	if(xe==xs)	{		k2=(y2-y1)/(x2-x1);		b2=y2-k2*x2;		xx=xe;		yy=k2*xx+b2;		return;	}	if(x2==x1)	{		k1=(ye-ys)/(xe-xs);		b1=ys-k1*xs;		xx=x2;		yy=k1*xx+b1;		return;	}	k1=(ye-ys)/(xe-xs);	k2=(y2-y1)/(x2-x1);	b1=ys-k1*xs;	b2=y2-k2*x2;	xx=(b1-b2)/(k2-k1);	yy=k1*xx+b1;}int main(){	int t;	scanf("%d",&t);	while(t--)	{		double x1,y1,x2,y2,xs,ys,xe,ye;		scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&xs,&ys,&xe,&ye);		duichendian(x1,y1,x2,y2,xs,ys);		jiaodian(xmi,ymi,xe,ye,x1,y1,x2,y2);		printf("%.3lf %.3lf\n",xx,yy);	}}


  相关解决方案