代码地址: 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的更多相关文章

  1. sicily 1059. Exocenter of a Trian

    Description Given a triangle ABC, the Extriangles of ABC are constructed as follows: On each side of ...

  2. poj1673 EXOCENTER OF A TRIANGLE

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

  3. POJ 1673 EXOCENTER OF A TRIANGLE(垂心)

    题目链接 折腾了半天,没想出怎么证明,以前初中老师教过,不知道怎么办,就量量...受不了,怒抄模版1Y... #include <cstdio> #include <iostream ...

  4. POJ 1673 EXOCENTER OF A TRIANGLE(解三角形重心)

    题目链接:http://poj.org/problem?id=1673 AC代码: #include<cstdio> #include<cmath> #include<a ...

  5. RNN 入门教程 Part 2 – 使用 numpy 和 theano 分别实现RNN模型

    转载 - Recurrent Neural Networks Tutorial, Part 2 – Implementing a RNN with Python, Numpy and Theano 本 ...

  6. k-折交叉验证(k-fold crossValidation)

    k-折交叉验证(k-fold crossValidation): 在机器学习中,将数据集A分为训练集(training set)B和测试集(test set)C,在样本量不充足的情况下,为了充分利用数 ...

  7. [转] POJ计算几何

    转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板 ...

  8. LIBSVM的使用方法

    [原文:http://wenku.baidu.com/view/7e7b6b896529647d27285276.html] 目  录 1 Libsvm下载... 3 2 Libsvm3.0环境变量设 ...

  9. poj1673

    所谓Exocenter就是垂心.不难证明. #include <iostream> #include <math.h> #include <stdio.h> str ...

随机推荐

  1. asp.net服务器控件开发系列一

    最近想写写博客记录下自己学习开发服务器控件. 第一步:搭建环境. 1.新建一个项目类库,用于保存控件: 2.新建一个Web工程,用于调用控件: 如图: 第二步:在控件类库下,新建一个服务器控件类Tex ...

  2. wel

    欢迎来到mathant.com 这个网站是什么 这个网站是我搭建在阿里云vps上的个人网站.目前的用途是充当个人博客和云存储,当然它的功能不止如此.我会在以后的日子里完善他,希望他能变得更好.目前我在 ...

  3. python模块学习 hashlib

    一.hashlib概述 涉及加密服务:14. Cryptographic Services 其中 hashlib是涉及安全散列和消息摘要,提供多个不同的加密算法借口,如SHA1.SHA224.SHA2 ...

  4. PLSQL性能优化技巧

    1.理解执行计划1-1.什么是执行计划 oracle数据库在执行sql语句时,oracle的优化器会根据一定的规则确定sql语句的执行路径,以确保sql语句能以最优性能执行.在oracle数据库系统中 ...

  5. Docker安装Gitlab

    一.Ubuntu16.4上Docker安装Gitlab 1.安装docker 参见:https://docs.docker.com/engine/installation/linux/ubuntuli ...

  6. source insight 使用技巧

    一.在所有文件中查找字符串 1.菜单栏选择“search project” 2.在随便一个工程文件中把所要查找的字符串输入到空白的地方,然后点连接

  7. keil对51单片机变量和函数的编译处理

    (1)初始值不是0的全局变量 在程序调到main()函数执行前,除了要进行内存清零.初始化堆栈外,还需要将全局变量的初始值加载到RAM的指定区域(编译过程中为全局变量分配的空间). (2)未初始化的局 ...

  8. 当xcode里点运行出现treating unicode character as whites

    可能是由于粘贴网页上的代码的时候两行之间的回车引起的,两行之间重新输入回车就行......删掉重新写一遍就ok了 引入网页上的回车时  可能  网页对其格式做了处理,所以Xcode  不认识了

  9. Java-反射再学习

    反射之中包含了一个“反”的概念,所以要想解释反射就必须先从“正”开始解释,一般而言,当用户使用一个类的时候,应该先知道这个类,而后通过这个类产生实例化对象,但是“反”指的是通过对象找到类. packa ...

  10. PAT (Basic Level) 1004. 成绩排名 (20)

    读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 学号 成绩 第3行:第2个学生 ...