NOJ[1329] Last Battle

本文介绍了一道算法题目,旨在寻找能够恰好覆盖三个指定点的最小圆,并计算该圆相对于由这三个点构成的三角形所浪费的面积。文章提供了完整的C语言实现代码,涉及坐标计算、距离公式及三角形面积计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • [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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值