代码地址: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1059.c

1059. Exocenter of a Trian

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Given a triangle ABC, the Extriangles of ABC are constructed as follows:

On each side of ABC, construct a square (ABDE, BCHJ and ACFG in the figure below).

Connect adjacent square corners to form the three Extriangles (AGD, BEJ and CFH in the figure).

The Exomedians of ABC are the medians of the Extriangles, which pass through vertices of the original triangle, extended into the original triangle (LAO, MBO and NCO in the figure. As the figure indicates, the three Exomedians intersect at a common point called the Exocenter (point O in the figure).

This problem is to write a program to compute the Exocenters of triangles.

Input

The first line of the input consists of a positive integer n, which is the number of datasets that follow. Each dataset consists of 3 lines; each line contains two floating point values which represent the (two -dimensional) coordinate of one vertex of a triangle. So, there are total of (n*3) + 1 lines of input. Note: All input triangles wi ll be strongly non-degenerate in that no vertex will be within one unit of the line through the other two vertices.

Output

For each dataset you must print out the coordinates of the Exocenter of the input triangle correct to four decimal places.

这题首先最重要的一点: 证明我们要求解的就是三角形ABC的垂心的坐标。

证明如下:

证明:

∵AK = A'K DK = GK ∠6 = ∠7

根据(SAS) ∴△AGK≌A'GK

∴∠1 = ∠4

又∵∠1 + ∠2 + ∠3 = 180°

∴∠2 + ∠3 + ∠4 = 180°

又∵∠3 + ∠4 + ∠5 = 180°

∴∠2 = ∠5

又∵AD = AB AG = AC

根据SAS ∴△ABC≌DAA'

∴∠3 = ∠8

又∵∠BAO + ∠3 = 90°

∴∠BAO + ∠8 = 90°

∴∠9 = 90°

同理∠10 = ∠11 = 90°

∴点O为高线交点 为△ABC的垂心

证毕。

好, 接下来是垂心的求解思路,很简单,设垂心坐标为(x, y), 三角形3个点坐标为(x1, y1) (x2, y2) (x3, y3)

用向量垂直来得到以下公式:

(x2 - x1)(x - x3) + (y2 - y1)(y - y3) = 0

(x3 - x1)(x - x2) + (y3 - y1)(y - y2) = 0

然后就求解这个方程组得到x, y就行了

但是这么做会有两个坑:

1. 不能输出-0.0000 所以最后结果输出的时候+个EPS就可以了。

2. 用向量计算的时候计算出x, 在计算y的时候,如果这时候使用的直线是平行于y轴的, 带入x将会输出错误的结果, 此时应换另一个直线方程做计算。

AC代码:

 1 #include <cstdio>
 2 #include <cmath>
 3
 4 #define EPS 1e-8
 5
 6 int main() {
 7     int t;
 8     double x1, y1, x2, y2, x3, y3, x, y;
 9     scanf("%d", &t);
10     while (t--) {
11         scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
12         x = (x3 * (x2 - x1) * (y3 - y1) - (y2 - y1) * ((x3 - x1) * x2 + (y2 - y3) * (y3 - y1)))
13             / ((x2 - x1) * (y3 - y1) + (y2 - y1) * (x1 - x3));
14         y = (fabs(x - x3) < EPS) ? y2 + (x3 - x1) * (x - x2) / (y1 - y3) : y3 + (x2 - x1) * (x - x3) / (y1 - y2);
15         printf("%.4f %.4f\n", x + EPS, y + EPS);
16     }
17     return 0;
18 }

转载于:https://www.cnblogs.com/laiy/p/sicily_1059.html

Sicily1059-Exocenter of a Trian相关推荐

  1. Sicily.1059. Exocenter of a Trian(求垂心,向量旋转)

    /* 1059. Exocenter of a Trian题目大意: 给出三角形ABC三点坐标,如图所示,作正方形ABDE,正方形BCHJ,正方形CAGF,L为DG中点,M为EJ中点,N为FH中点,直 ...

  2. poj1673 EXOCENTER OF A TRIANGLE

    地址:http://poj.org/problem?id=1673 题目: EXOCENTER OF A TRIANGLE Time Limit: 1000MS   Memory Limit: 100 ...

  3. trian和val结果相差很大。

    我说的是如果你含有BN层的话,有些人选择把BN层去掉之后,发现trian和val相差不大了. 存在的问题: 对训练集 accuracy可达0.99 loss=1e-2 -3,然而验证集 accurac ...

  4. 【tensorflow 训练验证数据处理】制制作trian和val TXT的文件

    开始训练模型之前,需要对收集的图片进行处理.那么第一步 就是制作trian和val TXT的文件. 训练和测试的图片数据集 分别放在 train 和val 两个文件夹下. 数据集,共有五类图片,分别是 ...

  5. tf.trian.match_filenames_once

    tf.trian.match_filenames_once  在构造datalist的时候经常使用,他可以利用正则表达式将需要的文件读出来作为一个list很好用,但是后面的的iterator要使用 i ...

  6. tensorflow——模型的保存和恢复tf.trian.saver()

    保存 1创建saver对象,确定save哪些:saver=tf.trian.Saver(),不填写参数的话默认全部 2指定在哪个session中保存,以及保存路径:saver.save(sess, ' ...

  7. POJ1673 EXOCENTER OF A TRIANGLE(三角形垂心)

    题目链接: http://poj.org/problem?id=1673 题目描述: EXOCENTER OF A TRIANGLE Description Given a triangle ABC, ...

  8. POJ 1673 EXOCENTER OF A TRIANGLE(证明+求三角形垂心)

    POJ 1673 EXOCENTER OF A TRIANGLE(证明+求三角形垂心) http://poj.org/problem?id=1673 题意: ZOJ 1821 有一个三角形ABC,扩展 ...

  9. POJ 1673 EXOCENTER OF A TRIANGLE(求三角形的垂心)

    博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/40654421 EXOCENTER OF A TRIANGLE 题目大意:一个三 ...

最新文章

  1. 每日站立会议12/23
  2. SQL Server中的高可用性----复制
  3. Socket连接与HTTP连接
  4. js调用c语言程序设计,HTML页面,测试JS对C函数的调用简单实例
  5. 实战Cisco路由器交换机各型号密码恢复
  6. Java Web 路径问题
  7. oracle使用max提升效率,Oracle调优之利用max与leftjoin来进行不同表之间匹配
  8. gitlab使用_使用 Docker 部署 Gitlab
  9. 1900 页数学基础:面向 CS 的线性代数、拓扑、微积分和最优化
  10. HDU-基础搜索总结
  11. 微型计算机的硬件系统普遍采用,2016年9月计算机一级《MS Office》考题与答案
  12. 网络安装Citrix XenServer
  13. C++中的左值和右值的区别
  14. ROS实战篇(一)如何在ROS中编写自己的package?------ 以节点通信为例
  15. ov5640帧率配置_OV5640摄像头开窗大小,输出窗口大小,帧率等设置
  16. P3324 [SDOI2015]星际战争二分答案+网络流
  17. MFC 句柄Hwnd 与 窗口Wnd的联系
  18. 华为官方翻新产品秒杀活动来袭,官方正品,7折优惠,真香!
  19. IEEEXTREME15.0 游记
  20. 歌单助手:一键导出网易云音乐歌单列表,推荐你喜爱的专辑

热门文章

  1. Rss Feed是什么?
  2. catagory,action,data隐式启动匹配规则
  3. php微信支付扫码源码下载,微信支付:扫码支付+APP支付
  4. MACBOOK快捷键输入
  5. pythonrsv分割_JavaScript是如何工作: 深入探索 websocket 和HTTP/2与SSE +如何选择正确的路径!...
  6. 查询宇宙生命的家谱--TaxonKit工具详解
  7. 今晚7:30 | 结构化知识的统一建模和多任务学习
  8. Masonry 比例设置multipliedBy与dividedBy区别
  9. html模拟终端,DomTerm:一款为Linux打造的终端模拟器
  10. VBA实现 Excel自动填充