据说这题是垂心。。数学太弱没有看出来,写了分朴实无华的代码。。
旋转三边得到图中的外顶点,然后连接三角形顶点求交点,交上WA。。觉得没什么错误就去看了下discuss,发现都在说精度问题,果断开始水,最后+了epsAC了。。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
}p[];
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
Point rotate(Point a,double rad)
{
return Point(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
bool intersection1(Point p1, Point p2, Point p3, Point p4, Point& p) // 直线相交
{
double a1, b1, c1, a2, b2, c2, d;
a1 = p1.y - p2.y;
b1 = p2.x - p1.x;
c1 = p1.x*p2.y - p2.x*p1.y;
a2 = p3.y - p4.y;
b2 = p4.x - p3.x;
c2 = p3.x*p4.y - p4.x*p3.y;
d = a1*b2 - a2*b1;
if (!dcmp(d)) return false;
p.x = (-c1*b2 + c2*b1) / d;
p.y = (-a1*c2 + a2*c1) / d;
return true;
}
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
double mul(Point p0,Point p1,Point p2)
{
return cross(p1-p0,p2-p0);
}
int main()
{
int n,i;
cin>>n;
while(n--)
{
for(i = ; i <= ; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
Point p1,p2,p3,p4;
if(dcmp(mul(p[],p[],p[]))>)
{
p1 = rotate(p[]-p[],*pi/2.0);
p2 = rotate(p[]-p[],pi/2.0);
}
else
{
p1 = rotate(p[]-p[],pi/2.0);
p2 = rotate(p[]-p[],*pi/2.0);
}
p1.x+=p[].x;
p1.y+=p[].y;
p2.x+=p[].x;
p2.y+=p[].y;
p1.x = (p1.x+p2.x)/;
p1.y = (p1.y+p2.y)/; if(dcmp(mul(p[],p[],p[]))>)
{
p3 = rotate(p[]-p[],*pi/2.0);
p4 = rotate(p[]-p[],pi/2.0);
}
else
{
p3 = rotate(p[]-p[],pi/2.0);
p4 = rotate(p[]-p[],*pi/2.0);
}
p3.x+=p[].x;
p3.y+=p[].y;
p4.x+=p[].x;
p4.y+=p[].y;
p3.x = (p3.x+p4.x)/;
p3.y = (p3.y+p4.y)/;
Point pp ;
intersection1(p1,p[],p3,p[],pp);
printf("%.4f %.4f\n",pp.x+eps,pp.y+eps); }
return ;
}