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

UVA10678 The Grazing Cow【椭圆面积】

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

A cow is grazing in the field. A rope in the field is tied with two pillars. The cow is kept tied with the rope with the help of a ring. So the cow can be considered to be tied with any point of the rope.Your job is to find the area of the field where the cow can reach and eat grass. If required assume that π = 2 ∗ cos−1(0) (Here angle is measured in radians). You can also assume that the thickness of the rope is zero, the cow is a point object and the radius of the ring and the thickness of the pillars are negligible. Please use double precision floating-point data type for floating-point calculations.
Input
First line of the input file contains an integer (N ≤ 100), which indicates how many sets of inputs are there. Each of the next N lines contains two integers D (0 ≤ D ≤ 1000) and L (D < L ≤ 1500). The first integer D denotes the distance in feet between the two pillars and the second integer L denotes the length of the rope in feet.
Output
Your program should produce N lines of output. Each line contains a single floating-point number, which has three digits after the decimal point. This floating-point number indicates the area of the field which the cow can reach and eat grass.
Sample Input
3
10 12
23 45
12 18
Sample Output
62.517
1366.999
189.670

问题链接UVA10678 The Grazing Cow
问题简述:计算椭圆的面积。
问题分析:裸题,计算椭圆面积。
程序说明:(略)
参考链接:(略)
题记:(略)

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

/* UVA10678 The Grazing Cow */

#include <bits/stdc++.h>

using namespace std;

const double PI = acos(-1.0);

int main()
{
    int n;
    scanf("%d", &n);
    while(n--) {
        double d, l;
        scanf("%lf%lf", &d, &l);
        double d2 = d * 0.5;
        double l2 = l * 0.5;
        printf("%.3f\n", PI * sqrt(l2 * l2 - d2 * d2) * l2);
    }

    return 0;
}