代码地址: 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. ACM YTU 挑战编程 字符串 Problem A: WERTYU

    Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...

  2. VS2008中MFC界面编程Caption中文全是乱码的解决办法 -转载

    一.问题 在预览状态下可能看到中文,但是编译运行后对话框中的中文全是问号.即使你用的VS中文版,即使你也用了Unicode编码,即使有条件编译 #ifdef _WIN32LANGUAGE LANG_C ...

  3. java设计模式——接口模式

    java将接口的概念提升为独立的结构,体现了接口与实现分离.java接口允许多个类提供相同的功能,也允许一个同时实现多个接口.java的接口与抽象类十分相似.java与抽象类中的区别: 1.一个类可以 ...

  4. js 中对象属性特性的描述

    如何自定义属性的特性? 用对象.属性的特性和自定义的属性的特性有什么区别? 它的四大特性 writable   enumerable   configable   有什么区别? 先预习一个用对象.属性 ...

  5. ubuntu npm 私有库搭建 (npmjs.org 官方版本)

    目标 npm.xxx.com 安装和推送nodejs包 npmui.xxx.com 管理已经推送的nodejs包   安装 couchdb   https://launchpad.net/~couch ...

  6. IS---InstallShield第二天

    在Setup.rul中,新增OnBegin函数 STRING str1,spath,szApplicationPath,szApplicationCmdLine,szCmdLine;function ...

  7. python的py文件打包成exe

    一.首先需要安装Pyinstaller-- 使用pip来安装模块 (我电脑上装的是python的一个编译环境Anaconda,如果电脑上装的是python自带的IDE的话,就直接进入python的安装 ...

  8. PinchEvent QML Type

    PinchEvent类型在QtQuick 1.1中被添加进来.center, startCenter, previousCenter属性保存了两个触摸点之间的中心位置.scale and previo ...

  9. css格式化排版

    1,文字排版--字体 语法: body{font-family:"Microsoft Yahei";} 这里注意不要设置不常用的字体,因为如果用户本地电脑上如果没有安装你设置的字体 ...

  10. WebApi学习总结系列第五篇(消息处理管道)

    引言: ASP.NET WebAPI的核心框架是一个消息处理管道,这个管道是一组HttpMessageHandler的有序组合.这是一个双工管道,请求消息从一端流入并依次经过所有HttpMessage ...