zoukankan      html  css  js  c++  java
  • Triangle

    在这里插入图片描述
    2019icpc Nanjing K
    比赛的时候怎么没想起来这么简单的做法啊

    #include <bits/stdc++.h>
    #pragma GCC optimize(3 , "Ofast" , "inline")
    using namespace std;
    const double eps = 1e-7 ;
    struct node
    {
       double x , y ;
       bool use ;
    }a[10] , b , e , c , d;
    double get(node a , node b)
    {
        return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) ;
    }
    double solve(node a , node b , node c , node d)
    {
        return (a.x - b.x) * (c.y - d.y) - (a.y - b.y) * (c.x - d.x) ;
    }
    double ask(node a , node b , node c , node d)
    {
        return (a.x - b.x) * (c.x - d.x) + (a.y - b.y) * (c.y - d.y) ;
    }
    void calc(node c , node e , double x)
    {
    //	printf("%.12lf %.12lf %.12lf %.12lf %.12lf
    " , c.x , c.y , e.x , e.y , x) ;
        node ce = {e.x - c.x , e.y - c.y , false} ;
        double t = get(c , e) ;
        ce.x = ce.x * x / t , ce.y = ce.y * x / t ;
        printf("%.12lf %.12lf
    " , ce.x + c.x , ce.y + c.y) ;
    }
    int main()
    {
        int T ;
        scanf("%d" , &T) ;
        while(T --)
        {
            int f = 0 ;
            for(int i = 1; i <= 3 ;i ++)
                 scanf("%lf%lf" , &a[i].x , &a[i].y) ;
            scanf("%lf%lf" , &b.x , &b.y) ;
            for(int i = 1; i <= 3 ;i ++)
            {
              for(int j = 1; j != i && j <= 3 ;j ++)
              {
                  double a1 = ask(a[i] , a[j] , a[i] , b) ;
                  double a2 = get(a[i] , a[j]) * get(a[i] , b) ;
                  double a3 = ask(a[j] , a[i] , a[j] , b) ;
                  double a4 = get(a[j] , a[i]) * get(a[j] , b) ;
                  if(abs(a1 - a2) <= eps && abs(a3 - a4) <= eps) 
                  {
                        e = a[6 - i - j] ;
                        a[i].use = a[j].use = true ;
                        f = 1; 
                        break ;
                  }
              }      
                if(f) break ;
            }
            if(!f) puts("-1") ;
            else 
            {
            f = 0 ;
            for(int i = 1; i <= 3 ;i ++)
            {
               for(int j = 1; j != i && j <= 3; j ++)
                    if(a[i].use && a[j].use) 
                    {
                        if(get(a[i] , b) >= get(a[j] , b))
                        {
                            c = a[i] , d = a[j] ;
                        }
                        else c = a[j] , d = a[i] ;
                        double x = get(c , e) * get(c , d) / (2 * get(c , b)) ;
                         calc(c , e , x) ;
                        f = 1 ;
                        
                        break ;
                    }
                if(f) break ;
            }
    		}
            
        }
        return 0 ;
    }
    
    每次做题提醒自己:题目到底有没有读懂,有没有分析彻底、算法够不够贪心、暴力够不够优雅。
  • 相关阅读:
    flexbox弹性盒子布局
    LAMP环境 源码包安装
    用条件注释判断浏览器版本,解决兼容问题
    事件冒泡和事件捕获
    为js和css文件自动添加版本号
    uEditor独立图片上传
    修改netbeans模版头部的说明
    thinkphp多表关联并且分页
    thinkphp 独立分组配置
    荣耀路由HiLink一键组网如何实现?
  • 原文地址:https://www.cnblogs.com/spnooyseed/p/12870870.html
Copyright © 2011-2022 走看看