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 ...
随机推荐
- SQL Server2008 附加数据库失败 错误代码5120
由于目录权限不够导致 ,解决办法:将文件所在的文件夹增加everyone 并且赋予完全控制权限问题解决
- vc调用BCB的dll 参数传递 报错
可能原因: 调用方式约定不一致. 函数调用约定如下: 1. __cdecl:C 和 C++ 程序的缺省调用规范. 2. __stdcall:标准调用约定(即WINAPI调用约定),也就是pascal调 ...
- python文件操作汇总
1.创建文件 f = open(filename,'w+')
- C# 之【获取网页响应码200】
做了个监控网站的C#项目,判断网站是否运行正常,采用的就是获取HTTP头返回的状态码. 比如状态码为200的就是网站正常,403是Forbidden,404是网页未找到这样. 代码如下: 首先是使用库 ...
- MFC可编辑的ListCtrl
近期由于项目的要求,需要一个可以编辑的列表控件,由于MFC提供的列表控件只支持第一行可编辑,无法满足项目需求,故只能自己动手重写一个列表控件.重写列表控件的思想为:当点击列表的某行某列时,在此处创建一 ...
- 18款js和jquery文字特效代码分享
18款js和jquery文字特效代码分享 jQCloud标签云插件_热门城市文字标签云代码 js 3d标签云特效关键词文字球状标签云代码 原生JS鼠标悬停文字球状放大显示效果代码 原生js文字动画圆形 ...
- winform下mapxtreme2008 v7.0 生成release版提示找不到dll问题
在winform下基于mapxtreme2008 v7.0 生成了一个地图软件,用debug方式运行无误,但改为release版时提示缺少一大堆dll,如: 无法从C:\Program Files ( ...
- demo_05HTML5+CSS3绘制小鸟
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- PHP 面向对对象基础(接口,类)
介绍PHP面向对象的基础知识 1. 接口的定义interface ,类定义class,类支持abstract和final修饰符,abstract修饰为抽象类,抽象类 不支持直接实例化,final修饰的 ...
- 移动端消除click事件的延迟效果
https://github.com/Plaputta/jquery.event.special.fastclick 用fastclick事件,类似zepto的tap事件,若想去除连点效果,可在外层显 ...