标签:sina const ios nbsp targe names puts solution ble
题目链接:https://nanti.jisuanke.com/t/A2226
题目大意:给定三角形三个顶点的坐标,判断是否可形成三角形,如果可形成三角形,求三角形内切圆面积与外接圆面积。
样例输入:
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
解题思路:假设三角形的三边长分别为a、b、c,面积为s
对于判断是否可形成三角形,我们可以直接判断三个顶点是否共线就好了
对于三角形内切圆半径r1,我们有1/2*a*r1+1/2*b*r1+1/2*c*r1=s => r1=2*s/(a+b+c);
对于三角形外接圆半径r2,我们根据正弦定理可得a/sinA=b/sinB=c/sinC=2*r2,而s=1/2*a*b*sinC=1/2*a*b*c/(2*r2) => r2=a*b*c/(4*s);
代码:
#include<iostream> #include<cmath> using namespace std; const double PI=acos(-1); const double eps=1e-6; int T,x1,y11,x2,y2,x3,y3; double jisuan(double x1,double y1,double x2,double y2){ //计算两点距离 return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main(){ cin>>T; while(T--){ cin>>x1>>y11>>x2>>y2>>x3>>y3; double a=jisuan(x1,y11,x2,y2); double b=jisuan(x1,y11,x3,y3); double c=jisuan(x3,y3,x2,y2); double p=(a+b+c)/2; double s=sqrt(p*(p-a)*(p-b)*(p-c)); //海伦公式求三角形面积 if((x1-x3)*(y2-y3)==(y11-y3)*(x2-x3)){ //判断三点是否共线 puts("NO SOLUTION"); continue; } double r1=2*s/(a+b+c); //内切圆半径 double r2=0.25*a*b*c/s; //外界圆半径 printf("%.10lf %.10lf\n",PI*r1*r1,PI*r2*r2); } return 0; }
标签:sina const ios nbsp targe names puts solution ble
原文地址:https://www.cnblogs.com/zjl192628928/p/10475305.html