POJ1927 Area in Triangle (计算几何)

Language:Default
Area in Triangle

Time Limit: 1000MSMemory Limit: 30000K
Total Submissions: 1694Accepted: 832

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

题意:
给定三角形的边a,b,c,和绳子长度d,求绳子在三角形内能围成的最大面积。
如果任意给定一条绳子,当绳子围成圆时面积最大。
三种情况

1当绳子长度大于等于三角形周长时,最大面积是三角形面积
2当绳子长度小于等于三角形内切圆周长时,最大面积是绳子围成的圆的面积
3介于两者之间时,尽量沿三角形边展开

这里写图片描述

此时面积是三角形面积S-小三角形面积s+小三角形内切圆面积s’

#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;

double solve(double a,double b,double c,double d){
    double Pi = acos(-1.0);
    double L = a+b+c;
    double cosA = (b*b+c*c-a*a)/(2*b*c);
    double S=sqrt(1-cosA*cosA)*0.5*b*c;
    double r = S*2/L;
    //printf("d---%.2lf L----%.2lf 2*Pi*r----%.2lf S----%.2lf\n",d,L,2*Pi*r,S);
    if(d>=L){
        return S;
    }
    else if(2*Pi*r>=d) return d*d/(4*Pi);//周长不如内切圆大
    else {
        double t = (L-d)/(L-2*Pi*r);
        //double t = (L-d)/L;
        double rr = r*t;
        return S-S*t*t+Pi*rr*rr;

    }
}
int main()
{
    double a,b,c,d;
    int cas=0;
    while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d)!=EOF)
    {

        if(a==0&&b==0&&c==0&&d==0) break;
        else{
                double ans;
                ans = solve(a,b,c,d);
                printf("Case %d: %.2lf\n",++cas,ans);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值