NOJ[1329] Last Battle

  • [1329] Last Battle

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • TT and her army exterminated the big boss and his demons successfully, but TT's army suffered great losses. they met the final boss, what? another TT! dont worry, that was just a disguise. This boss divided himself into three parts, at(x1,y1),(x2,y2)and(x3,y3)and made a triangle. TT decide to concentrate her power too, she could create a circle to cover this three point to defeat the boss. TT want to find out the smallest circle, also she want to know how many power was wasted to destroy the triangle.

  • 输入
  • There are many cases. For each case, there are three coordinates(-100 <= xi,yi <= 100),means three boss's position.
  • 输出
  • For each case, first line print the coordinate of the circle, second line print the wasted area of the circle. Keep two decimal point please.
  • 样例输入
  • -1 0 1 0 0 1
    -2 0 4 0 1 6
  • 样例输出
  • 0.00 0.00 1.00
    2.14
    1.00 2.25 3.75
    26.18
    
    
    
    
    
  • 提示
  • 来源
  • Mr.Cai

这题本质就是求三角形的外接圆,外心就是中垂线的交点,把方程解出来就没什么了,然后注意pi的精度。

#include<stdio.h>
#include<math.h>

const double pi=acos(-1);

double dist(double x1,double y1,double x2,double y2)
{
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

double cross(double x1,double y1,double x2,double y2)
{
  return (x1*y2-x2*y1);
}

int main()
{
  double x1,y1,x2,y2,x3,y3;
  while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3))
  {
    double J=4*((x1-x2)*(y1-y3)-(y1-y2)*(x1-x3));
    double t1=(x1*x1-x2*x2+y1*y1-y2*y2);
    double t2=(x1*x1-x3*x3+y1*y1-y3*y3);
    double x=2*(t1*(y1-y3)-t2*(y1-y2))/J;
    if(x<=1e-2 && x>=-1e-2)
      x=0;
    double y=2*(t2*(x1-x2)-t1*(x1-x3))/J;
    if(y<=1e-2 && y>=-1e-2)
      y=0;
    double r=dist(x,y,x1,y1);
    printf("%.2f %.2f %.2f\n",x,y,r );
    double circle_area=pi*r*r;
    double triangle_area=fabs(cross(x2-x1,y2-y1,x3-x1,y3-y1))/2;
    printf("%.2f\n",circle_area-triangle_area );
  }
  return 0;
}


你可能感兴趣的:(NOJ[1329] Last Battle)