Area in Triangle
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 1674 | Accepted: 821 |
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.
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 The
third case: picking someone else's picture
// Mathematics 1 General Exercise 2 // POJ 1927 Find the maximum area of a figure with a certain perimeter inside a triangle // The meaning of the question: Given the length of the three sides of a triangle and the length of a rope, what is the maximum area that can be enclosed by the rope in the triangle // The law of cosines : // cosA=b^2+c^2-a^2/2*bc // cosB=a^2+c^2-b^2/2*ac // cosC=a^2 +b^2-c^2/2*ab // triangle area formula // S=0.5*bc*sinA=0.5*bc*(1-cosA^2) // triangle inscribed circle radius: // r=2S/(a+b+c) // If the rope is long enough and the length >= the perimeter of the triangle, then the maximum area that can be enclosed is the area of the triangle // If the length of the rope <= the inscribed circumference of the triangle, then the maximum area is to enclose the rope into a circle (because a plane figure with equal perimeter must have the largest area of a circle, probably in junior high school) // . What if it's somewhere in between? // Then go to the blog by yourself
//Find the similarity ratio
//xsb=(Cd)/(C-2*PI*R)
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm > using namespace std; const double PI=acos(-1.0); const double eps=1e-8; double a,b,c,d; int dcmp( double x) { return x<-eps?-1:x>eps; } intmain () { int cas=0; while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d)) { if(!dcmp(a)&&!dcmp(b)&&!dcmp(c)&&!dcmp(d)) break; ++cas; double C=a+b+c; double cosA=(b*b+c*c-a*a)/(2*b*c); double S=0.5*b*c*sqrt(1-cosA*cosA); double R=S*2/C; if(d>C) //直接围三角形 printf("Case %d: %.2lf\n",cas,S); else if(d<=2*PI*R) // The length of the rope <= the length of the inscribed circle, around a circle printf( " Case %d: %.2lf\n " ,cas,d*d/( 4 * PI)); else // Look at the blog and go to { double xsb =(Cd)/(C- 2 *PI*R); // Similar ratio double r=R* xsb; printf("Case %d: %.2lf\n",cas,S-S*xsb*xsb+PI*r*r); } } return 0; }