欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVA11152 Safe Salutations【计算几何】

程序员文章站 2022-03-02 10:58:18
...

“Roses are red, violets are blue…”
Millionaire Mr Smith is well-known — not for his wealth, but for his odd sense of “art”… Mr Smith has got a circular garden. On the boundary he picks three points and gets a triangle. He then finds the largest circle in that triangular region. So he gets something like this:
Mr Smith then plants yellow sunflowers, blue violets and red roses in the way shown in the figure. (Nice combination,
eh? ???? Given the lengths of the three sides of the triangle, you are to find the areas of the regions with each kind of flowers
respectively.
UVA11152 Safe Salutations【计算几何】
Input
Each line of input contains three integers a, b, c, the lengths of the three sides of the triangular region, with 0 < a ≤ b ≤ c ≤
1000.
Output
For each case, your program should output the areas of the regions with sunflowers, with violets and with roses respectively. Print your answers correct to 4 decimal places.
Sample Input
3 4 5
Sample Output
13.6350 2.8584 3.1416

问题链接UVA11152 Safe Salutations
问题简述:(略)
问题分析:(略)
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11152 Safe Salutations */

#include <bits/stdc++.h>

using namespace std;

const double PI = acos(-1);

int main()
{
    double a, b, c;
    while(~scanf("%lf%lf%lf", &a, &b, &c)) {
        // 海伦定理,计算三角形面积
        double s = 0.25 * sqrt((a + b + c)*(a + b - c)*(a + c - b) * (b + c - a));
        // 计算内切圆半径:r*(a+b+c) = s
        double r = 2 * s / (a + b + c);
        // 余弦定理,计算角A
        double cosa = (b * b + c * c - a * a) / (2 * b * c);
        // 正弦定理,求外接圆半径 a/(2*R) = sinA
        double R = a / (2 * sqrt(1 - cosa * cosa));

        printf("%.4f %.4f %.4f\n", R * R * PI - s, s - r * r * PI, r * r * PI);
    }

    return 0;
}