2019icpc Nanjing K
比赛的时候怎么没想起来这么简单的做法啊
#include <bits/stdc++.h>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std;
const double eps = 1e-7 ;
struct node
{
double x , y ;
bool use ;
}a[10] , b , e , c , d;
double get(node a , node b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) ;
}
double solve(node a , node b , node c , node d)
{
return (a.x - b.x) * (c.y - d.y) - (a.y - b.y) * (c.x - d.x) ;
}
double ask(node a , node b , node c , node d)
{
return (a.x - b.x) * (c.x - d.x) + (a.y - b.y) * (c.y - d.y) ;
}
void calc(node c , node e , double x)
{
// printf("%.12lf %.12lf %.12lf %.12lf %.12lf
" , c.x , c.y , e.x , e.y , x) ;
node ce = {e.x - c.x , e.y - c.y , false} ;
double t = get(c , e) ;
ce.x = ce.x * x / t , ce.y = ce.y * x / t ;
printf("%.12lf %.12lf
" , ce.x + c.x , ce.y + c.y) ;
}
int main()
{
int T ;
scanf("%d" , &T) ;
while(T --)
{
int f = 0 ;
for(int i = 1; i <= 3 ;i ++)
scanf("%lf%lf" , &a[i].x , &a[i].y) ;
scanf("%lf%lf" , &b.x , &b.y) ;
for(int i = 1; i <= 3 ;i ++)
{
for(int j = 1; j != i && j <= 3 ;j ++)
{
double a1 = ask(a[i] , a[j] , a[i] , b) ;
double a2 = get(a[i] , a[j]) * get(a[i] , b) ;
double a3 = ask(a[j] , a[i] , a[j] , b) ;
double a4 = get(a[j] , a[i]) * get(a[j] , b) ;
if(abs(a1 - a2) <= eps && abs(a3 - a4) <= eps)
{
e = a[6 - i - j] ;
a[i].use = a[j].use = true ;
f = 1;
break ;
}
}
if(f) break ;
}
if(!f) puts("-1") ;
else
{
f = 0 ;
for(int i = 1; i <= 3 ;i ++)
{
for(int j = 1; j != i && j <= 3; j ++)
if(a[i].use && a[j].use)
{
if(get(a[i] , b) >= get(a[j] , b))
{
c = a[i] , d = a[j] ;
}
else c = a[j] , d = a[i] ;
double x = get(c , e) * get(c , d) / (2 * get(c , b)) ;
calc(c , e , x) ;
f = 1 ;
break ;
}
if(f) break ;
}
}
}
return 0 ;
}