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;
    }

  • 相关阅读:
    .NetCore 部署到IIS上的问题
    泛型(EF)增删改查
    Ef数据GroupBy多字段查询Vb.net与c#参考
    WEBAPI 最近更新项目时 服务器总是提示:An error has occurred.
    SQL SERVER 语法
    Fonour.AspnetCore 生成SQL SERVER数据库
    Windows10出现打开EXE应用程序错误
    jQuery实现DOM加载方法源码分析
    前端面试高频题:删除数组重复元素的多种方法
    Mac 下使用homebrew 安装node后全局安装找不到问题
  • 原文地址:https://www.cnblogs.com/zhanhb/p/2103184.html
Copyright © 2011-2022 走看看