POJ-1927 Area in Triangle解题报告

Description

Given a triangle field and a rope of a certain length (Figure-1), you are required to use the rope to enclose a region within the field and make the region as large as possible.

Input

The input has several sets of test data. Each set is one line containing four numbers separated by a space. The first three indicate the lengths of the edges of the triangle field, and the fourth is the length of the rope. Each of the four numbers have exactly four digits after the decimal point. The line containing four zeros ends the input and should not be processed. You can assume each of the edges are not longer than 100.0000 and the length of the rope is not longer than the perimeter of the field.

Output

Output one line for each case in the following format:

Case i: X

Where i is the case number, and X is the largest area which is rounded to two digits after the decimal point.

Sample Input

12.0000 23.0000 17.0000 40.0000
84.0000 35.0000 91.0000 210.0000
100.0000 100.0000 100.0000 181.3800
0 0 0 0

Sample Output

Case 1: 89.35
Case 2: 1470.00
Case 3: 2618.00
题目链接:http://poj.org/problem?id=1927
题目大意:给你三角形的三边长及一段绳子的长度,要求你求出绳子在三角形内能围成的最大面积。
题目思路:我们可以想到,有三种情况,一种是绳长比三边和都大,那么围成的最大面积显然是三角形的面积(面积用海伦公式易求)。第二种是绳长大于等于三角形内切圆的周长,此时绳子围成的最大面积显然是在三角形内,最大面积即绳子围城的圆面积。最后一种是不属于上述两种的其余情况,我们想象把绳子在三角形内尽量扩展而不出三角形的区域,这样会形成三段弧以及三段和三边贴合的部分(画个图很容易看),就近似三个小三角形,三个小三角形看成一个完整的新三角形,三段弧连接便是新三角形的内切圆,三角形的周长比为内切圆半径比,面积为内切圆半径比的平方,由此,我们可以计算出新三角形的面积s,原三角形的面积S,新三角形的内切圆面积s1,则围城的面积即为S-s+s1(减去新三角形为多减去其内切圆的面积,故需再加上),内切圆半径r=2*s/(a+b+c),然后根据两三角形周长比等于半径比求出新三角形的内切圆半径r,最后求出面积(在草稿上推导下就出来了)。
实现代码:
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
const double PI=acos(-1.0);
int main()
{
	double a,b,c,L;
	int cout=1;
	while(cin>>a>>b>>c>>L)
	{
		if(a==0&&b==0&&c==0&&L==0)
			break;
		double p=(a+b+c)/2.0;//海伦公式中的参量p。
		double S=sqrt(p*(p-a)*(p-b)*(p-c));//海伦公式求面积。
		double R=S/p;//内切圆半径=2*s/(a+b+c);
		if(L>=a+b+c)
			printf("Case %d: %.2lf\n",cout++,S);//比三角形周长还长,则最大围住三角形的区域。
		else if(L<=PI*R*2)
			printf("Case %d: %.2lf\n",cout++,L*L/(4*PI));//比三角形的内切圆区域小,则最大区域为绳子围成的圆。
		else
		{
			double r=R*(2*p-L)/(2*p-2*PI*R);//l/(2*P)=r/R,l=2*P-L+2*PI*r,小三角形周长=大三角形周长减去绳长,但多减了小三角形的内切圆的周长,故加上。
			double s=(r/R)*(r/R)*S;
			printf("Case %d: %.2lf\n",cout++,S-s+PI*r*r);
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值