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. 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚 dp/线段树

    题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...

  2. C# 利用FTP自动下载xml文件后利用 FileSystemWatcher 监控目录下文件变化并自动更新数据库

    using FtpLib; using System; using System.Collections.Generic; using System.ComponentModel; using Sys ...

  3. IntellIJ IDEA 配置 Maven

    一.配置Maven环境 1.下载apache-maven文件,选择自己需要的版本 2.解压1所下载文件,E:\apache-maven-3.5.4 3.配置Maven环境变量 a. MAVEN_HOM ...

  4. POJ2728:Desert King——题解

    http://poj.org/problem?id=2728 题目大意:求一棵生成树使得路费用和/路长之和最小(路的费用是两端点的高度差) 最小比率生成树. 我们还是01分数规划的思想将边权变为路费用 ...

  5. NOIP2015Day2T2子串(字符串dp)

    又被“if(a=b)”坑了QAQ...写C++还是得开Warning,这么久了pascal还没改过来咋回事啊QWQ 题目大意就不说了OWO 网上的题解都不怎么看得懂啊...好像写得都很乱?还是我太sb ...

  6. 【单调队列】【P1714】 切蛋糕

    传送门 Description 今天是小Z的生日,同学们为他带来了一块蛋糕.这块蛋糕是一个长方体,被用不同色彩分成了N个相同的小块,每小块都有对应的幸运值. 小Z作为寿星,自然希望吃到的第一块蛋糕的幸 ...

  7. C/C++中二维数组和指针关系分析

    在C/c++中,数组和指针有着密切的关系,有很多地方说数组就是指针式错误的一种说法.这两者是不同的数据结构.其实,在C/c++中没有所谓的二维数组,书面表达就是数组的数组.我猜想是为了表述方便才叫它二 ...

  8. HDU 1715 大数java

    大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. Codeforces Round #530 (Div. 2):D. Sum in the tree (题解)

    D. Sum in the tree 题目链接:https://codeforces.com/contest/1099/problem/D 题意: 给出一棵树,以及每个点的si,这里的si代表从i号结 ...

  10. 使用springcloud的feign调用服务时出现的错误:关于实体转换成json错误的介绍

    http://blog.csdn.net/java_huashan/article/details/46428971 原因:实体中没有添加无参的构造函数 fastjson的解释: http://www ...