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

UVA10573 Geometry Paradox【计算几何】

程序员文章站 2022-03-02 10:55:24
...

In the picture below you can see two small circles touching each other. The larger circle touches both of them. The length of the common tangent inscribed inside the larger circle is t and the radiuses of the two smaller circles are r1 and r2. The centers of the three circles are collinear. You will be given the value of r1 and r2 or the value of t. You will have to find the area that is within the larger circle but out of the two smaller circles (marked gray in the picture). If the given data is not enough to find the gray area, print the line ‘Impossible.’ in a single line
UVA10573 Geometry Paradox【计算几何】
Input
First line of the input file contains an integer N (N ≤ 100) which denotes how many sets of inputs are there. Each of the next N lines contain a set of input.
    Each set either contains one or two integer. If it contains one integer then it is the value of t, otherwise the two values are the values of r1 and r2. All these integers are less than 100
Output
For each line of input produce one line of output. This line contains the area of the gray part if the given information is enough to find the area of the gray part. Otherwise it contains the line ‘Impossible’. The area should have four digits after the decimal point. Assume that π = 2 ∗ cos−1(0).
Sample Input
2
10 10
15 20
Sample Output
628.3185
1884.9556

问题链接UVA10573 Geometry Paradox
问题简述:两个相切的小圆r1,r2,同时外切于一个大圆R。已知两小圆的半径分别为r1和r2,给定被大圆截取的两个小圆共同的切线段长度为t,求大圆面积减去两小圆面积为多少。
问题分析
    分析如下:
大圆半径R = r1 + r2
t×t = 4(RR-(r2-r1)^2)= 4r1r2
得:
S = π(R
R - r1r1 - r2r2)= π 2r1r2 = π t*t / 8。
    需要注意数据输入格式。
程序说明:(略)
参考链接:(略)
题记:(略)

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

/* UVA10573 Geometry Paradox */

#include <bits/stdc++.h>

using namespace std;

const double PI = 2 * acos(0.0);

int main()
{
    int n;
    string s;
    double r1, r2;

    scanf("%d", &n);
    getline(cin, s);
    while(n--) {
        getline(cin , s);
        if(sscanf(s.c_str(), "%lf%lf", &r1, &r2) == 1) {
            if(r1 >= 0) printf("%.4f\n", PI * r1 * r1 * 0.125);
            else printf("Impossible.\n");
        } else {
            if (r1 >= 0 && r2 >= 0) printf("%.4f\n", PI * r1 * r2 * 2.0);
            else printf("Impossible.\n");
        }
    }

    return 0;
}