犄角之势

题目大意:给定三角形三个顶点的坐标,判断是否可形成三角形,如果可形成三角形,求三角形内切圆面积与外接圆面积。

输入格式
第一行一个整数 T,表示数据的组数。接下来 T 行,每行 6 个整数 x1,y1,x2,y2,x3,y3 表示三个点的坐标
输出格式
对于每组数据,如果不能组成三角形,输出"NO SOLUTION",否则输出两个空格分隔的实数,分别表示内切圆和外接圆的面积。相对误差或者绝对误差在 10^-6范围内就认为是正确的。

样例输入:

4
0 3 4 0 0 0
0 0 10 10 -10 -10
3 3 5 3 3 5
0 0 -5 -10 5 -10

样例输出:

3.1415926536 19.6349540849
NO SOLUTION
1.0780241689 6.2831853072
29.9995403716 122.7184630309

#include <cstdio>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
const int inf=0x7fffffff;
const long long mod=1e9+7;
const double PI=acos(-1);                      //PI的定义方式
double juli(int x1,int y1,int x2,int y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{    
    int t;
    int x1,y1,x2,y2,x3,y3;
    cin>>t;
    while(t--){
        cin>>x1>>y1>>x2>>y2>>x3>>y3;
        if((x1-x3)*(y2-y3)==(x2-x3)*(y1-y3)){
            cout<<"NO SOLUTION"<<endl;
            continue;
        }
        double a=juli(x1,y1,x2,y2);
        double b=juli(x1,y1,x3,y3);
        double c=juli(x2,y2,x3,y3);
        double p=(a+b+c)/2;
        double s=sqrt(p*(p-a)*(p-b)*(p-c));        //海伦公式求面积 
        double r1=2*s/(a+b+c);                       //三角形内切圆半径 
        double r2=0.25*a*b*c/s;                    //三角形外接圆半径 
        printf("%.10lf %.10lf\n",r1*r1*PI,r2*r2*PI);
    }
    return 0;
}

 

posted @ 2020-03-04 20:25  Maxwell·  阅读(274)  评论(0编辑  收藏  举报