zoukankan      html  css  js  c++  java
  • 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;
        double y;
    };
    struct Line
    {
        double a;
        double b;
        double c;
    };
    
    Point get_point1(Line x,Line y)
    {
        return (Point){ (x.b*y.c-y.b*x.c)/(x.a*y.b-y.a*x.b) , (y.a*x.c-x.a*y.c)/(x.a*y.b-y.a*x.b) };
    }
    
    Point extent1(Point a,Point b)
    {
        return (Point){2*b.x-a.x,2*b.y-a.y};
    }
    
    Line get_line1(Point a,Point b)
    {
        return (Line){ a.y-b.y , b.x-a.x , a.y*(a.x-b.x)-a.x*(a.y-b.y) };
    }
    
    Line get_line1(Point a,Line x)
    {
        return (Line){ -x.b , x.a , x.b*a.x-x.a*a.y };
    }
    
    int main()
    {
        //freopen("1005.in","r",stdin);
        scanf("%d",&t);
        Point ans;
        Point s,e,tmp,m1,m2,news;
        Line a,b,c;
        while(t--)
        {
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y11,&x2,&y2,&xs,&ys,&xe,&ye);
            m1.x=x1;m1.y=y11;
            m2.x=x2;m2.y=y2;
            s=(Point){xs,ys},e=(Point){xe,ye};
            //get
            b=get_line1(m1,m2);
            a=get_line1(s,b);
    
            tmp=get_point1(a,b);
            news=extent1(s,tmp);
            c=get_line1(news,e);
            ans=get_point1(c,b);
            if(fabs(ans.x-0.000)<1e-6)
                ans.x=0.000;
            if(fabs(ans.y-0.000)<1e-6)
                ans.y=0.000;
            printf("%.3lf %.3lf
    ",ans.x,ans.y);
        }
        return 0;
    }
  • 相关阅读:
    hdu 5045 Contest
    hdu 4068 SanguoSHA
    TSP 旅行商问题(状态压缩dp)
    haoi2015 树上操作
    noi 2015 软件包管理器(树链剖分)
    zjoi2008 树链剖分
    读入优化
    动态规划类型总结
    有关Rujia Liu 动态规划的·一些总结
    输入优化
  • 原文地址:https://www.cnblogs.com/BBBob/p/6522916.html
Copyright © 2011-2022 走看看