Area in Triangle

题目链接:http://poj.org/problem?id=1927

题目:

题目大意:给定一个三角形的三条边长和一根绳子的长度,求这根绳子在三角行内所能围成的最大面积

显然,围成的图形为圆形方能使面积最大化,因为当周长一定是,圆形的面积最大,

这么来有三种情况,圆在三角形内,三角形为圆的内接三角形,或者图形与三角形边相切。

利用海伦公式求三角形面积:已知三角形ABC三边为a,b,c

p=(a+b+c)/2

∴SΔ=√[p(p+a)(p+b)(p+c)]  (海伦公式)

前两种就不说了,说说第三种,如图:

如图:绳子这样围成面积最大(弧长dc+cb+弧长ba+af+弧长fe+ed)且三个扇形会构成一个整圆o,与O1,O2,O3相连的直线都垂直三角形

绳长 - 三边小弧长 = 大三角形周长 - (eC + Cf + aA + Ab + cB + Bd,下面设为t ) = ( 三条粗线长)

                           r:R = t:大三角形周长(r为三个扇形构成的圆的半径,R为大三角形内切圆的半径) 这是因为三角形相似 过大三角形的内切圆圆心分别做各边的垂线(图未画出)就可以清楚的看出CfO3e这个四边形以及另外两个构成了一个三角形且与大三角形相似,三个扇形构成的圆是构成的三角形的内切圆。

大三角形周长

大三角形周长

                           通过以上就可以求出r了,所以answer = 大三角形面积S - 构成的小三角形的面积(S*(r*r)/(R*R)  等比性质) + 构成的小圆面积

 

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
 
 
#include<stdio.h>
#include<math.h>
const double pi=acos(-1.0);
int main()
{
  double a,b,c,len;
  int i=0;
  while(scanf("%lf%lf%lf%lf",&a,&b,&c,&len)!=EOF)
  {
	  i++;
	  double p,s,R,r,max=0;
	  if(a==0||b==0||c==0)
		  break;
	  p=(a+b+c)/2;
	  s=sqrt(p*(p-a)*(p-b)*(p-c));  //s代表面积
	  R=2*s/(a+b+c);
	  if(len>=2*p)
		  max=s;
	  else if(len<=pi*R*2)
		  max=pi*(len/(2*pi))*(len/(2*pi));
	  //if(len>pi*R*2&&len<2*p)
	 else
	  {
         r=(len-2*p)/(2*pi-2*p/R);
		 max=pi*r*r+s-(s*(r*r)/(R*R));
	  }
	  printf("Case %d: %.2lf\n",i,max);
  }
  return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值