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. CentOS 访问控制列表(tcp wrappers)

    1.TCP Wrappers是一个工作在应用层的安全工具,它只能针对某些具体的应用或者服务起到一定的防护作用.比如说ssh.telnet.FTP等服务的请求,都会先受到TCP Wrappers的拦截. ...

  2. CentOS 设置环境变量

    1. 查看环境变量,echo 命令用于在终端输出字符串或变量提取后的值,格式为“echo [字符串 | $变量]” echo $PATH /usr/local/bin:/usr/bin:/usr/lo ...

  3. [洛谷P4168][Violet]蒲公英

    题目大意:有$n(n\leqslant4\times10^4)$个数,$m(m\leqslant5\times10^4)$个询问,每次问区间$[l,r]$内的众数,若相同输出最小的,强制在线. 题解: ...

  4. NOIP 2018 -The Wound-

    "一招不慎,满盘皆输" 如果这个盘是整整一年的OI生涯的话 那么"一招"一定就是NOIP了 Update 2019/4/6 剧变的一年 noip这个成绩意味着我 ...

  5. BZOJ1058:[ZJOI2007]报表统计——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=1058 https://www.luogu.org/problemnew/show/P1110#su ...

  6. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  7. 【初级算法】2.买卖股票的最佳时机 II

    题目: 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易(你必 ...

  8. Django内置auth模块中login_required装饰器用于类视图的优雅方式

    使用多继承 以及类似java中的静态代理模式 原理:OrderView.as_view()根据广度优先,调用的是LoginRequiredMixin中的as_view(cls, *args, **kw ...

  9. POJ1236:Network of Schools (思维+Tarjan缩点)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24880   Accepted: 99 ...

  10. derby数据库windows自带的客户端

    本示例演示用windows自带的ij来操作derby数据库,包括建库,建表,插入数据,查询数据 首先要配置环境变量: 其次打开cmd输入如下图所示的命令: java代码如下: package com. ...