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 Source |
[Submit] [Go Back] [Status] [Discuss]
题意:
给一个三角形和一根绳子,求绳子在三角形内能围出的最大面积
solution:
分类讨论如下:
1.绳子很长,,如果比三边长之和还长,输出三角形面积即可
2.绳子很短,,如果比内接圆周长还短,输出绳子围一个圆的面积即可
3.这时绳子肯定是在三边上各有分布,之间用圆弧相连,可以把三个顶端和在一起,做一个小三角and小圆(画图),,,瞎比模拟之
细节处理不到位
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
using namespace std;
typedef double DB;
const DB eps = 1E-10;
const DB pi = 3.14159265358979;
DB a,b,c,L,two = 2.00;
bool Judge() {return a <= eps && b <= eps && c <= eps && L <= eps;}
int main()
{
for (int i = 1; ; i++) {
scanf("%lf%lf%lf%lf",&a,&b,&c,&L);
if (Judge()) break;
DB p = (a + b + c)/two;
DB s = sqrt(p*(p - a)*(p - b)*(p - c));
if (a + b + c - L <= eps) {printf("Case %d: %.2lf\n",i,s); continue;}
DB r = two*s/(a+b+c);
if (two*pi*r - L >= eps) {
DB R = L/pi/two;
printf("Case %d: %.2lf\n",i,pi*R*R);
continue;
}
DB x = (a+b+c-L);
DB Lk = eps,Rk = 1.00;
for (int j = 0; j < 100; j++) {
DB mid = (Lk+Rk)/two;
DB ck = mid*(a+b+c-two*pi*r);
if (ck > x) Rk = mid; else Lk = mid;
}
DB sk = Rk*Rk*(s-pi*r*r);
printf("Case %d: %.2lf\n",i,s - sk);
}
return 0;
}