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

hdu oval-and-rectangle

程序员文章站 2023-12-26 12:32:33
...

                            oval-and-rectangle

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)

Total Submission(s) : 5   Accepted Submission(s) : 4

Problem Description

Patrick Star find an oval.

The half of longer axes is on the x-axis with length $a$.

The half of shorter axes is on the y-axis with length $b$.

Patrick Star plan to choose a real number $c$ randomly from $[0, b]$, after that, Patrick Star will get a rectangle :

1. The four vertexes of it are on the outline of the oval.

2. The two sides of it parallel to coordinate axis.

3. One of its side is $y = c$.

Patrick Star want to know the expectations of the rectangle's perimeter.

 

 

Input

The first line contain a integer $T$ (no morn than 10), the following is $T$ test case, for each test case : Each line contains contains two integer a, b ($0 < b < a < 10^5$). Separated by an white space.

 

 

Output

For each test case output one line denotes the expectations of the rectangle's perimeter . You should keep exactly 6 decimal digits and ignore the remain decimal digits. It is guaranted that the 7-th decimal digit of answer wont be 0 or 9.

 

 

Sample Input

 

1 2 1

 

 

Sample Output

 

8.283185

 

 

Source

2018 Multi-University Training Contest 6

其实就是让求均值,把所有可能周长加起来除去变化范围即可

首先要求出周长公式

我们都知道椭圆的公式

我们知道y的变化范围是[0,b][0,b],并且我们可以求出x用y表示

 

hdu oval-and-rectangle

因为题目要求保留6位小数,并且后面的全部舍去,因此为了防止%.6f造成四舍五入,因此给答案-0.0000005

 

#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1)
int main()
{
    int t,a,b;
    double s;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&a,&b);
        s=a*PI+2*b-0.0000005;
        printf("%.6lf\n",s);
    }
}

 

上一篇:

下一篇: