标签:des style blog http color java os io strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 814 Accepted Submission(s): 385
题目大意:给一面镜子(一直线),给一入射光经过的点跟反射光经过的点,求入射点。
思路:求一个点关于镜子的对称点,与另一点与镜子的交点就是入射点。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 7 const double eps=1e-10; 8 const double Pi=acos(-1.0); 9 struct Point 10 { 11 double x,y; 12 Point(double x=0,double y=0):x(x),y(y) {} 13 }; 14 typedef Point Vector; 15 Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);} 16 Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);} 17 Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);} 18 int dcmp(double x) 19 { 20 if(fabs(x)<eps) return 0; 21 else return x<0?-1:1; 22 } 23 24 double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积 25 double Length(Vector A){return sqrt(Dot(A,A));}//向量的长度 26 double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}//两向量的夹角 27 double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积 28 Point GetLineProjection(Point P,Point A,Point B)//P在直线AB上的投影点 29 { 30 Vector v=B-A; 31 return A+v*(Dot(v,P-A)/Dot(v,v)); 32 } 33 Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)//两直线的交点 34 { 35 Vector u=P-Q; 36 double t=Cross(w,u)/Cross(v,w); 37 return P+v*t; 38 } 39 40 Point read_point() 41 { 42 Point p; 43 scanf("%lf%lf",&p.x,&p.y); 44 return p; 45 } 46 int main() 47 { 48 int t; 49 Point p1,p2,p3,p4,p5; 50 scanf("%d",&t); 51 while(t--) 52 { 53 p1=read_point();p2=read_point();p3=read_point();p4=read_point(); 54 p5= GetLineProjection(p3,p1,p2); 55 p5=p3+(p5-p3)*2; 56 p5=GetLineIntersection(p5,p5-p4,p1,p2-p1); 57 printf("%.3lf %.3lf\n",p5.x,p5.y); 58 } 59 return 0; 60 }
标签:des style blog http color java os io strong
原文地址:http://www.cnblogs.com/xiong-/p/3930489.html