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.

Sample Input
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard 
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
Sample Output
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的更多相关文章

  1. Sicily1059-Exocenter of a Trian

    代码地址: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1059.c 1059. Exocenter of a ...

  2. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  3. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  4. ytu 1059: 判别该年份是否闰年(水题,宏定义)

    1059: 判别该年份是否闰年 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 222  Solved: 139[Submit][Status][Web ...

  5. 【BZOJ】1059: [ZJOI2007]矩阵游戏(二分图匹配)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1059 本题可以看出,无论怎样变化,在同一行和同一列的数永远都不会分手---还是吐槽,,我第一眼yy了 ...

  6. 【BZOJ】【1059】【ZJOI2007】矩阵游戏

    二分图完美匹配/匈牙利算法 如果a[i][j]为黑点,我们就连边 i->j ,然后跑二分图最大匹配,看是否有完美匹配. <_<我们先考虑行变换:对于第 i 行,如果它第 j 位是黑点 ...

  7. 大数求模 sicily 1020

        Search

  8. Sicily 1510欢迎提出优化方案

    这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...

  9. bzoj 1059: [ZJOI2007]矩阵游戏 二分图匹配

    1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1891  Solved: 919[Submit][Statu ...

随机推荐

  1. BZOJ 1221 软件开发(费用流)

    容易看出这是显然的费用流模型. 把每天需要的餐巾数作为限制.需要将天数拆点,x’表示每天需要的餐巾,x’’表示每天用完的餐巾.所以加边 (s,x',INF,0),(x'',t,INF,0). 餐巾可以 ...

  2. [SOJ #48]集合对称差卷积

    题目大意:给你两个多项式$A,B$,求多项式$C$使得: $$C_n=\sum\limits_{x\oplus y=n}A_xB_y$$题解:$FWT$ 卡点:无 C++ Code: #include ...

  3. BZOJ4552:[HEOI2016/TJOI2016]排序——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=4552 https://www.luogu.org/problemnew/show/P2824 在2 ...

  4. 洛谷1578:[WC2002]奶牛浴场——题解

    https://www.luogu.org/problemnew/show/P1578#sub 由于John建造了牛场围栏,激起了奶牛的愤怒,奶牛的产奶量急剧减少.为了讨好奶牛,John决定在牛场中建 ...

  5. 全面解析JavaScript的Backbone.js框架中的Router路由

    这篇文章主要介绍了Backbone.js框架中的Router路由功能,Router在Backbone中相当于一个MVC框架中的Controller控制器功能,需要的朋友可以参考下. Backbone ...

  6. 什么是static?什么是final?

    由static修饰的变量.常量.和方法被称为是静态变量.常量和 方法. 静态数据和静态方法的作用通常是为了提供共享数据或方法,如数学计算公式等,以static声明并且实现,这样当需要使用时,直接使用类 ...

  7. 学习opencv-------函数使用二(图像变换)

    #include"cv.h" #include"highgui.h" using namespace cv; void CVFILTER2D(IplImage ...

  8. 第01篇 为什么推荐使用String直接赋值

    在四海学的时候,可能需要我们经过沉淀才会去想一些事情,有的时候不知道为什么这样或者那样的时候,从今天看是,胖先生打算给大家开辟一个课程,就是我的读书笔记. 首先我们来认识一下String字符串 一般对 ...

  9. JS判断内容为空方法总结

    HTML代码: 用户名:<input type="text" id="username"> <p style="color:red& ...

  10. idea中设置springboot热部署

    在idea中设置springboot热部署,项目修改的时候不用手动重启应用 1,pom中添加依赖 <dependency> <groupId>org.springframewo ...