sicily 1059. Exocenter of a Trian
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.

For each dataset you must print out the coordinates of the Exocenter of the input triangle correct to four decimal places.
2
0.0 0.0
9.0 12.0
14.0 0.0
3.0 4.0
13.0 19.0
2.0 -10.0
9.0000 3.7500
-48.0400 23.3600
分析:这题要求的点其实就是三角形的垂心,那么只要根据三角形坐标求得垂心的坐标即可,我是根据斜率乘积是 - 来求解方程式而得到结果的。但是这样做的话要注意斜率不存在的情况,所以一共有 种情况(分母为 ),还要注意的是 double 对 的处理,也即下面的 dcmp 函数。这样处理显得有点,乱,特别是在公式处理。但是只要自己把公式列出来还是能很快理解的。另外这里将三个点排序的原因是这样处理后能使得三个点的相对位置明确,减少可能出现的斜率为零的情况。
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; const double eps = 1e-; struct Point{
double x;
double y;
}; bool cmp(const Point &a, const Point &b) {
return a.x < b.x;
} int dcmp(double x){
return (x > -eps && x < eps) ? : ;
} int main(int argc, char const *argv[])
{
int testNum;
cin >> testNum;
Point point[];
while (testNum--) {
for (int i = ; i != ; ++i) {
cin >> point[i].x >> point[i].y;
}
sort(point, point + , cmp); double x1_sub_x2 = point[].x - point[].x;
double y2_sub_y1 = point[].y - point[].y;
double x2_sub_x3 = point[].x - point[].x;
double y3_sub_y2 = point[].y - point[].y;
double x3_sub_s1 = point[].x - point[].x;
double y3_sub_y1 = point[].y - point[].y;
double x, y;
if (dcmp(x1_sub_x2) == ) {
x = point[].x;
y = point[].y;
} else if (dcmp(y2_sub_y1) == ) {
x = point[].x;
y = point[].y - (x2_sub_x3 / y3_sub_y2) * (-x3_sub_s1);
} else if (dcmp(x2_sub_x3) == ) {
y = point[].y;
x = (-y2_sub_y1) * y3_sub_y1 / x1_sub_x2 + point[].x;
} else if (dcmp(x3_sub_s1) == ) {
y = point[].y;
x = point[].x + y3_sub_y1 * y2_sub_y1 / (-x1_sub_x2);
} else {
x = (y3_sub_y1 - (x1_sub_x2 / y2_sub_y1) * point[].x +
(x2_sub_x3 / y3_sub_y2) * point[].x) / (x2_sub_x3 / y3_sub_y2 - x1_sub_x2 / y2_sub_y1);
y = point[].y - (x2_sub_x3 / y3_sub_y2) * (point[].x - x);
} x = dcmp(x) == ? : x;
y = dcmp(y) == ? : y;
printf("%.4lf %.4lf\n", x, y);
}
return ;
}
sicily 1059. Exocenter of a Trian的更多相关文章
- Sicily1059-Exocenter of a Trian
代码地址: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1059.c 1059. Exocenter of a ...
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- ytu 1059: 判别该年份是否闰年(水题,宏定义)
1059: 判别该年份是否闰年 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 222 Solved: 139[Submit][Status][Web ...
- 【BZOJ】1059: [ZJOI2007]矩阵游戏(二分图匹配)
http://www.lydsy.com/JudgeOnline/problem.php?id=1059 本题可以看出,无论怎样变化,在同一行和同一列的数永远都不会分手---还是吐槽,,我第一眼yy了 ...
- 【BZOJ】【1059】【ZJOI2007】矩阵游戏
二分图完美匹配/匈牙利算法 如果a[i][j]为黑点,我们就连边 i->j ,然后跑二分图最大匹配,看是否有完美匹配. <_<我们先考虑行变换:对于第 i 行,如果它第 j 位是黑点 ...
- 大数求模 sicily 1020
Search
- Sicily 1510欢迎提出优化方案
这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...
- bzoj 1059: [ZJOI2007]矩阵游戏 二分图匹配
1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1891 Solved: 919[Submit][Statu ...
随机推荐
- CF546E Soldier and Traveling
题目描述 In the country there are n n n cities and m m m bidirectional roads between them. Each city has ...
- [洛谷P4980]【模板】Polya定理
题目大意:给一个$n$个点的环染色,有$n$中颜色,问有多少种涂色方案是的旋转后本质不同 题解:$burnside$引理:$ans=\dfrac1{|G|}\sum\limits_{g\in G}A_ ...
- bzoj1263: [SCOI2006]整数划分(高精度+构造)
第一次写压位高精度只好抄黄学长的 代码最后一段想了好久一看评论区才知道黄学长写错了= =很气 自己最后改对了T^T 这题最优是一直划分3出来直到<=4 #include<iostream& ...
- bzoj1656: [Usaco2006 Jan] The Grove 树木 (bfs+新姿势)
题目大意:一个n*m的图中,“.”可走,“X”不可走,“*”为起点,问从起点开始绕所有X一圈回到起点最少需要走多少步. 一开始看到这题,自己脑洞了下怎么写,应该是可过,然后跑去看了题解,又学会了一 ...
- Nginx漏洞利用与安全加固
本文主要分为两大部分,第一部分介绍了Nginx的一些常见安全漏洞的形成原因.利用方法,并给出了相应的解决办法;第二部分介绍了Nginx安全加固时需要关注的主要内容. Nginx(发音同engine x ...
- SELECT LOCK IN SHARE MODE and FOR UPDATE
Baronwrote nice article comparing locking hints in MySQL and SQL Server. In MySQL/Innodb LOCK IN SHA ...
- ACE中UDP通信
转载于:http://www.cnblogs.com/TianFang/archive/2006/12/07/585205.html udp是一种无连接的协议,提供无连接不可靠的服务. 在ace中,通 ...
- POJ 3421分解质因数
X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7375 Accepted: 2340 D ...
- HDU1832 二维线段树求最值(模板)
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- Caused by: java.io.IOException: Filesystem closed的处理
org.apache.hadoop.hive.ql.metadata.HiveException: Unable to rename output from: hdfs://nameservice/u ...