物理渣只能搜题解了。。
分三种情况
1、len>=a+b+c
2、len<内切圆半径 圆的面积是最大的 --》以len为周长的圆
3、看这篇http://blog.sina.com.cn/s/blog_6a46cc3f0100tujn.html
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include<set> 10 using namespace std; 11 #define N 100000 12 #define LL long long 13 #define INF 0xfffffff 14 const double eps = 1e-8; 15 const double pi = acos(-1.0); 16 const double inf = ~0u>>2; 17 int dcmp(double x) 18 { 19 if(fabs(x)<eps) return 0; 20 else return x<0?-1:1; 21 } 22 int main() 23 { 24 double a,b,c,l; 25 int kk = 0; 26 while(scanf("%lf%lf%lf%lf",&a,&b,&c,&l)!=EOF) 27 { 28 if(fabs(a)<eps&&fabs(b)<eps&&fabs(c)<eps&&fabs(l)<eps) break; 29 double p = (a+b+c)/2; 30 double area = sqrt(p*(p-a)*(p-b)*(p-c)); 31 double r = sqrt((p-a)*(p-b)*(p-c)/p); 32 double ans ; 33 if(dcmp(2*pi*r-l)>=0) 34 { 35 ans = l*l/(4*pi); 36 //cout<<"2"<<endl; 37 } 38 else if(dcmp(l-a-b-c)>=0) 39 { 40 ans = area; 41 //cout<<"1"<<endl; 42 } 43 else 44 { 45 double k = (a+b+c-l)/(a+b+c-2*pi*r); 46 r*=k; 47 ans = area-area*k*k+pi*r*r; 48 // cout<<"3"<<endl; 49 } 50 printf("Case %d: %.2f\n",++kk,ans); 51 } 52 return 0; 53 }
poj1927Area in Triangle
时间: 2024-10-28 12:50:33