问题 C: 【计算几何】Area in Triangle

151 篇文章 8 订阅

有一种隐忍其实是蕴藏着的一种力量,有一种静默其实是惊天的告白。

题目描述

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. 

 

输入

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 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. 

 

样例输入

复制样例数据

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

样例输出

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

题解:1当绳子长度大于等于三角形周长时,最大面积是三角形面积

2当绳子长度小于等于三角形内切圆周长时,最大面积是绳子围成的圆的面积

3介于两者之间时,尽量沿三角形边展开

图片来自于:https://blog.csdn.net/hanyanwei123/article/details/81782952

#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<iomanip>
#include<algorithm>
#define inf 0x3f3f3f3f
#define pi 3.1415926
typedef long long ll;
using namespace std;
int main(){
    double s1,s2,s3,cd,mx,r,qy,R,l,L;
    int i=1;
    while(~scanf("%lf%lf%lf%lf",&s1,&s2,&s3,&cd)&&(s1+s2+s3+cd)!=0.0){
        L=s1+s2+s3;
        l=L/2.0;
        qy=sqrt(l*(l-s1)*(l-s2)*(l-s3));
        R=qy*2.0/L;
        if(L<=cd)
            mx=qy;
        else if(2.0*pi*R>=cd)
            mx=cd*cd/(4.0*pi);
        else{
            r=(L-cd)/(L/R-2.0*pi);
            mx=qy+pi*r*r-(r*r*qy/(R*R));
        }
        printf("Case %d: %.2lf\n",i,mx);
        i++;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值