Area in Triangle (计算几何)

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

这道题目的意思就是给你一个三角形和一根绳要求用绳在三角形内围出最大的面积。又是一道数学题目,今天脑袋很晕,只想做一定水题的,

不过这个题目想了一会,唯一要注意的是精度问题。参考了很多博客,不过有很多是不能AC的代码,很迷。

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const double PI=acos(-1);
int main()
{
	double a,b,c,d,l,max,R,r,t,area;
	int count=1;
	scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
	while(a+b+c+d)
	{
		t=a+b+c;
		l=t*0.5;
		area=sqrt(l*(l-a)*(l-b)*(l-c));
		R=area*2.0/t;
		if(a+b+c<=d)
			max=area;
		else if(2.0*PI*R>=d)
			max=d*d/(4.0*PI);
		else
		{
			r=(a+b+c-d)/((a+b+c)/R-2.0*PI);
			max=area+PI*r*r-(r*r*area/(R*R));
		}
		printf("Case %d: %.2f\n",count++,max);
		scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值