HDU 1451 Area in Triangle(相似三角形)

来源:互联网 发布:java 引用class文件 编辑:程序博客网 时间:2024/05/16 08:37

Area in Triangle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 221    Accepted Submission(s): 63


Problem 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.000084.0000 35.0000 91.0000 210.0000100.0000 100.0000 100.0000 181.38000 0 0 0
 

Sample Output
Case 1: 89.35Case 2: 1470.00Case 3: 2618.00
 

Source
ACM暑期集训队练习赛(六)

题目大意:给你三角形的三边长,给你一根绳长,问线能在三角形中围成的最大面积。
这道题目需要分情况讨论
1.如果绳子比三角形周长长,那么围成的最大面积就是三角形面积。
2.绳子比三角形周长短。
2.1绳子比三角形内切圆的周长短。
    我们要知道,在平面内,在周长一定的情况下,圆的面积最大。
所以围成的最大面积为以绳长为周长的圆的面积。
2.2绳子比三角形内切圆的周长长

  那么绳子肯定会与三角形的三条边都有贴合的部分,贴合的部分可以看成三个矩形,未贴合的部分就是三个圆弧,三个圆弧可以组成里面相似三角形的内切圆。(图不是很标准)
利用的就是三角形相似的原理;

公式;p0/R*(R-r)=len-2*pi*R;

左边是通过内切圆半径与周长的关系求得小三角形的周长;右边是通过自由线的长度减掉三段弧得到相似三角形的周长;
那么最后的围成的最大面积就是相似三角形面积+相似三角形内切圆面积+三个矩形的面积
以下是AC代码
#include<cstdio>#include<cmath>using namespace std;#define eps 1e-9#define pi acos(-1.0)int main(){ int T=0; double a,b,c,len,p0,p1,S,R,r; //len为自由线的长度;p0为原三角形的周长;p1为原三角形的半周长;  //R为原三角形的内切圆半径;r为相似三角形的内切圆半径。  while(scanf("%lf%lf%lf%lf",&a,&b,&c,&len),a+b+c+len) {   printf("Case %d: ",++T);   p0=a+b+c;   p1=p0/2;   S=sqrt(p1*(p1-a)*(p1-b)*(p1-c));   if(len>=p0)  {printf("%.2lf\n",S);continue;} //自由线长大于三角形周长   R=2*S/p0; //三角形内切圆公式S=p0*R/2; R为内切圆半径   if(2*pi*R-len>eps)   {     R=len/pi/2;     S=pi*R*R;     printf("%.2lf\n",S);     continue;   }  //利用的就是三角形相似的原理;公式;p0/R*(R-r)=len-2*pi*R;左边是通过内切圆半径与周长的关系求  //得小三角形的周长;右边是通过自由线的长度减掉三段弧得到相似三角形的周长;  r=(p0-len)/(p0/R-2*pi);//三角形相似  a=a/R*(R-r); b=b/R*(R-r);  c=c/R*(R-r);  double p=(a+b+c)/2;  S=pi*r*r+sqrt(p*(p-a)*(p-b)*(p-c))+r*(a+b+c);//分三个部分求面积  printf("%.2lf\n",S); }}
原题链接:HDU 1451