POJ 1927 Area in Triangle 題解
Description
給出三角形三邊長,給出繩長,問繩在三角形內能圍成的最大面積。保證繩長 \(\le\) 三角形周長。
Solution
首先我們得知道,三角形的內切圓半徑就是三角形面積 \(\times 2\) 除以三角形周長。
可以看出,如果繩長 \(\le\) 三角形內切圓周長,那麼我們肯定是圍成一個圓。否則,我們就會圍成下圖形狀:
考慮計算面積:
可以發現的是圖中所指出的形狀相等,以及小三角形與大三角形相似。那麼我們就可以聯立方程,解出小圓的半徑,然後就可以算了。
Code
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define Int register int
#define MAXN
template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}
template <typename T> inline void chkmax (T &a,T b){a = max (a,b);}
template <typename T> inline void chkmin (T &a,T b){a = min (a,b);}
double a,b,c,d,pi = acos (-1);
signed main(){
int cnt = 0;
while (~scanf ("%lf%lf%lf%lf",&a,&b,&c,&d)){
if (a + b + c + d == 0) return 0;
printf ("Case %d: ",++ cnt);
double L = a + b + c,t = L / 2,S = sqrt (t * (t - a) * (t - b) * (t - c)),R = S / t;
if (d <= 2 * pi * R) printf ("%.2f\n",d * d / (4 * pi));
else{
double r = (L - d) / (L / R - 2 * pi),l = L - (d - 2 * pi * r),s = l * r / 2;
printf ("%.2f\n",S - s + r * r * pi);
}
}
return 0;
}