Area in Triangle

Insert picture description here
Samples
Input Copy
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
Output
Case 1: 89.35
Case 2: 1470.00
Case 3: 2618.00

Question: Give you the length of three sides of a triangle, and then give you the length of a rope. Ask you the largest area enclosed in the triangle?
Idea: There
are three situations:

  • 1. When the given rope length is greater than or equal to the circumference of the triangle, then the largest area enclosed must be the triangle itself.
  • 2. When the given rope length is less than or equal to the inscribed circumference of the triangle, the maximum area enclosed is the circle enclosed by this rope length, and the rope length is the circumference.
    1. Between them, we find a similar triangle. The triangle formed by the difference in side length is similar to the original triangle.
      Insert picture description here
#include <map>
#include <queue>
#include <string>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pii;
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << ": " << x << endl;
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<=(b);++i)
#define repr(i,b,a) for(int i=int(b);i>=(a);--i)
const int maxn=2e5+1010;
#define inf 0x3f3f3f3f
#define sf scanf
#define pf printf
const int mod=1e9+7;
const int MOD=10007;
double qpow(double a,ll b) {
    
    
    double ans=1;
    while(b) {
    
    
        if(b&1) ans=ans*a;
        b>>=1;
        a=a*a;
    }
    return ans;
}

int main() {
    
    
    double a,b,c,sum;
    ll T=0;
    while(cin>>a>>b>>c>>sum){
    
    
        if(!a&&!b&&!c&&!sum) break;
        double pi=acos(-1);
        double l=a+b+c;
        double ja=(b*b+c*c-a*a)/(2*b*c);
        double s=0.5*b*c*sqrt(1-ja*ja);
        double r=s*2/l;
        if(sum>=l) {
    
    
            printf("Case %lld: %.2lf\n",++T,s);
        }else {
    
    
            if(2*pi*r>=sum){
    
    
                printf("Case %lld: %.2lf\n",++T,sum*sum/(4*pi));
            }else {
    
    
            double bi=(l-sum)/(l-2*pi*r);
            double ans1=r*bi;
            printf("Case %lld: %.2lf\n",++T,s-s*bi*bi+pi*ans1*ans1);
            }
        }

    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45911397/article/details/114379015