Sicily1059-Exocenter of a Trian
代码地址: 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代码:
#include <cstdio>
#include <cmath> #define EPS 1e-8 int main() {
int t;
double x1, y1, x2, y2, x3, y3, x, y;
scanf("%d", &t);
while (t--) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
x = (x3 * (x2 - x1) * (y3 - y1) - (y2 - y1) * ((x3 - x1) * x2 + (y2 - y3) * (y3 - y1)))
/ ((x2 - x1) * (y3 - y1) + (y2 - y1) * (x1 - x3));
y = (fabs(x - x3) < EPS) ? y2 + (x3 - x1) * (x - x2) / (y1 - y3) : y3 + (x2 - x1) * (x - x3) / (y1 - y2);
printf("%.4f %.4f\n", x + EPS, y + EPS);
}
return ;
}
Sicily1059-Exocenter of a Trian的更多相关文章
- sicily 1059. Exocenter of a Trian
Description Given a triangle ABC, the Extriangles of ABC are constructed as follows: On each side of ...
- poj1673 EXOCENTER OF A TRIANGLE
地址:http://poj.org/problem?id=1673 题目: EXOCENTER OF A TRIANGLE Time Limit: 1000MS Memory Limit: 100 ...
- POJ 1673 EXOCENTER OF A TRIANGLE(垂心)
题目链接 折腾了半天,没想出怎么证明,以前初中老师教过,不知道怎么办,就量量...受不了,怒抄模版1Y... #include <cstdio> #include <iostream ...
- POJ 1673 EXOCENTER OF A TRIANGLE(解三角形重心)
题目链接:http://poj.org/problem?id=1673 AC代码: #include<cstdio> #include<cmath> #include<a ...
- RNN 入门教程 Part 2 – 使用 numpy 和 theano 分别实现RNN模型
转载 - Recurrent Neural Networks Tutorial, Part 2 – Implementing a RNN with Python, Numpy and Theano 本 ...
- k-折交叉验证(k-fold crossValidation)
k-折交叉验证(k-fold crossValidation): 在机器学习中,将数据集A分为训练集(training set)B和测试集(test set)C,在样本量不充足的情况下,为了充分利用数 ...
- [转] POJ计算几何
转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板 ...
- LIBSVM的使用方法
[原文:http://wenku.baidu.com/view/7e7b6b896529647d27285276.html] 目 录 1 Libsvm下载... 3 2 Libsvm3.0环境变量设 ...
- poj1673
所谓Exocenter就是垂心.不难证明. #include <iostream> #include <math.h> #include <stdio.h> str ...
随机推荐
- oracle redo日志维护
环境 OS:Red Hat Linux As 5 DB:10.2.0.1 1.添加日志组 alter database add logfile group 4 ('/u01/app/oracle/or ...
- tomcat环境变量配置
先下载tomcat的压缩包(绿色版),解压到C盘目录下即可. 在系统坏境中配置(高级系统设置>环境变量>系统变量) 新建变量名:CATALINA_HOME,变量值:C:\apache-to ...
- Objective-C中的@dynamic(转)
转自 http://blog.csdn.net/haishu_zheng/article/details/12873151 Objective-C中的@dynamic 一.@dynamic与@synt ...
- why slow thinking wins
今天Hacker News上的一篇文章<为什么想得慢的人能赢>引起了广泛的讨论. 网友Scott Burson在文章后评论说:"之前,我雇佣了一位TopCoder冠军,原本预计他 ...
- php中如何实现网上商城用户历史浏览记录的代码
/如是COOKIE 里面不为空,则往里面增加一个商品ID if (!empty($_COOKIE['SHOP']['history'])){ //取得COOKIE里面的值,并用逗号把它切割成一个数组 ...
- 《paste命令》-linux命令五分钟系列之二十
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...
- 将小度WiFi改造为无线网卡(小度WiFi能够接收WiFi信号)
安装官方的小度WiFi的驱动器,只能让它当做无线信号的发射装置,但是我想通过小度WiFi让我的台式电脑能都接收无线信号,于是经过一番折腾终于成功了.我的是win7. 小度WiFi无法接受无线信号,不能 ...
- app上传 需要的icon
如果提交的ipa包中,未包含必要的Icon就会收到类似的通知,为什么偏偏是Icon-76呢? 因为我们开发的游戏,默认是支持iphone以及ipad的,根据官方提供的参考 Icon-76.png是必须 ...
- tomcat发布静态网页
- JavaScriptCore-b
JavaScriptCore提供了JavaScript和Objective-C桥接的Obj-C API.JavaScriptCore提供了让我们脱离UIWebView执行JavaScript脚本的能力 ...