zoukankan      html  css  js  c++  java
  • 没事做,贴个代码。

    Problem E

    Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 11    Accepted Submission(s): 2
    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.
     
    SampleInput
    1
    0.000 0.000
    4.000 0.000
    1.000 1.000
    3.000 1.000
     
    SampleOutput
    2.000 0.000 
     

    #include<stdio.h>
    #include<math.h>
    #include<iostream>

    #define abs(double) ((double)>0?(double):-(double))
    #define eps 0.0000001

    using namespace std;

    struct point{
     double x,y;
     friend istream&operator>>(istream&in,point &p){
      in>>p.x>>p.y;
      return in;
     }
     friend ostream&operator<<(ostream&out,point p){
      out<<p.x<<' '<<p.y<<endl;
      return out;
     }
    };
    struct line{
     bool inf;
     double k,b;
     friend istream&operator>>(istream&in,line&l){
      l.inf=false;
      in>>l.k>>l.b;
      return in;
     }
     friend ostream&operator<<(ostream&out,line l){
      if(l.inf)out<<' '<<l.b<<endl;
      else out<<l.k<<' '<<l.b<<endl;
      return out;
     }
     friend point operator*(line l1,line l2){
      point t;
      if(l1.inf){
       t.x=l1.b;
       t.y=l2.k*t.x+l2.b;
      }else if(l2.inf){
       t.x=l2.b;
       t.y=l1.k*t.x+l1.b;
      }else{
       t.x=(l2.b-l1.b)/(l1.k-l2.k);
       t.y=l1.k*t.x+l1.b;
      }
      return t;
     }
    };
    line point2line(point a,point b){
     line t;
     t.inf=abs(a.x-b.x)<eps;
     if(t.inf){
      t.b=a.x;
     }else{
      t.k=(a.y-b.y)/(a.x-b.x);
      t.b=a.y-t.k*a.x;
     }
     return t;
    }
    point pointcalc(point p,line l){
     point t;
     if(l.inf){
      t.x=l.b*2-p.x;
      t.y=p.y;
     }else{
      t.x=((1-l.k*l.k)*p.x+2*l.k*p.y-2*l.k*l.b)/(1+l.k*l.k);
      t.y=((l.k*l.k-1)*p.y+2*l.k*p.x+2*l.b)/(1+l.k*l.k);
     }
     return t;
    }
    int main(){
     int cas;
     line t1,t2;
     point a,b,c,d,x;
     cin>>cas;
     while(cas--){
      cin>>a>>b>>c>>d;
      x=pointcalc(c,t1=point2line(a,b));
      //cout<<t1<<x<<d;
      t2=point2line(x,d);
      //cout<<t2;
      c=t1*t2;
      printf("%.3f %.3f\n",c.x,c.y);
     }
     return 0;
    }

  • 相关阅读:
    html更改弹窗样式(原创,转载需声明)
    关于考研的反思
    Android之控件学习
    Android之LinearLayout布局下怎么让按钮固定在底部
    Android中控件属性详细总结(转载)
    毕业设计周记(第四篇)
    毕业设计周记(第三篇)
    毕业设计周记(第二篇)
    毕业设计周记(第一篇)
    Hadoop
  • 原文地址:https://www.cnblogs.com/zhanhb/p/2103184.html
Copyright © 2011-2022 走看看