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 ...
随机推荐
- C# Ref 与out 的区别
在C#中,有四种传递参数方式: 1. 传值 (value) : 无额外修饰符 2. 传址(reference) : 需修饰符Ref,传入函数的参数必须先赋值 3. 输出参数(output): 需修饰符 ...
- 组策略彻底解决windows 2003 终端数
win2003的话可以从组策略修改: 组策略级别要高于终端服务配置,当启用组策略后终端服务配置中的相应选项会变成灰色不可修改 运行-gpedit.msc-计算机配置-管理模板-Windows ...
- Oracle学习【索引及触发器】
索引B_Tree结构 请参照 响应图例 索引是一种允许直接访问数据表中某一数据行的树形结构,为了提高查询效率而引入,是独立于表的对象,可以存放在与表不同的表空间中.索引记录中存有索引关键字和指向表中数 ...
- linux下安装mysql5.6(官方文档)
Using the MySQL Yum Repository / Installing MySQL on Linux Using the MySQL Yum Repository Chapter ...
- 工具: ass109.awk 分析 Oracle 的跟踪文件
原文链接:http://www.eygle.com/archives/2009/11/awk_ass109.html 以前分析Oracle的跟踪文件,主要靠手工阅读,最近发现ass109.awk文件是 ...
- c语言中文件相关操作
一 .首先介绍一下数据文件的类型: 1.二进制文件(映像文件):在内存中以二进制形式存取. 2.文本文件(ascii文件):以ascii码形式存取的文件. 通俗的讲,在Mac下,你把一个文件丢进记事本 ...
- 从ZOJ2114(Transportation Network)到Link-cut-tree(LCT)
[热烈庆祝ZOJ回归] [首先声明:LCT≠动态树,前者是一种数据结构,而后者是一类问题,即:LCT—解决—>动态树] Link-cut-tree(下文统称LCT)是一种强大的数据结构,不仅可以 ...
- ecshop添加自定义lbi文件
1.找到 admin下面 includes\lib_template.php 找到 $page_libs = array( 这里…. 给您需要的页面加上 你自己的 boke365.lbi 2.找到 l ...
- BitMap(比特位)
所谓的Bit-map就是用一个bit位来标记某个元素对应的Value, 而Key即是该元素.由于采用了Bit为单位来存储数据,因此在存储空间方面,可以大大节省. 腾讯面试的时候,让写了一个BitMap ...
- Android学习3—电话拨号器
本测试主要实现了一个Android的拨打电话的功能 一:界面预览 由图中可以看出,这个Activity需要3个控件:TextView.EditText.Button 其实实现一个功能要经过几个步骤: ...