Live2D

POJ 1927 Area in Triangle 题解

link

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;
}
posted @ 2022-02-05 11:14  Dark_Romance  阅读(61)  评论(0编辑  收藏  举报