poj 1927 计算几何 解题报告

Area in Triangle

Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 1513 Accepted: 774
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.

题解

三种情况。
撑开的绳子有三种形状:l>=a+b+c时,是三角形;l<=内切圆周长时,是圆形;其余都是圆角三角形。
(因为同样的周长圆的面积最大~)
我们发现三个角上的不规则图形刚好可以拼起来变成一个与大三角形相似的小三角形-与大圆相似的小圆,其中两图形的相似比相同。所以我们可以列方程求解小圆半径。
设大圆半径R,小圆半径r,三角形三边a,b,c和a,b,c,那么我们可以用海伦公式求出大三角形面积S。
然后,因为2*S=(A+B+C)*R,所以我们又可以求出来R。
然后列方程:
(A+B+C)(R-r)/R+2π*r=l
解方程求得r,最后的结果即为s-s*r*r/R/R+r*r*π~
注意第二种情况答案不是内切圆的面积!

代码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
double solve(double a,double b,double c,double d)
{
    double L,Pi,cosA,S,r;
    Pi=acos(-1.0);
    L=a+b+c;
    cosA=(b*b+c*c-a*a)/(2*b*c);
    S=0.5*b*c*(sqrt(1-cosA*cosA));
    r=S*2/L;
    if (d>L) return S;
    else if (2*Pi*r>=d) return d*d/(4*Pi);
    else 
    {
        double t,rr;
        t=(L-d)/(L-2*Pi*r);
        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;
        cas++;
        printf("Case %d:%0.2lf\n",cas,solve(a,b,c,d));
    }
    return 0;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值