HDU 6362 oval-and-rectangle (多校水题)

hdu 6362

题目:

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

 

 

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

题意:一个椭圆中心在原点, 长半轴长a,短半轴长b, 一个一组边平行于y轴的矩形四个顶点在椭圆上, 且平行于y轴的边长为2c(0 <= c <= b) 求该矩形周长的期望值 。

题解:期望值就是结果*概率的加和, 而这个题的不同周长的矩形有“无限多”个, 且每个结果出现的概率都是相等的而且是极其“微小”的, 所以这里我们可以用乘法分配, 直接计算全体周长的和然后再除以微小概率的集合b, 即期望值。

HDU 6362 oval-and-rectangle (多校水题)_第1张图片

高数功底不行, 推这个用尽了我全部查克拉~~~

AC代码:

#include
using namespace std;

int main()
{
    double pi = acos(-1.0);
    int T;
    cin >> T;
    while(T--){
        int a, b;
        double ans;
        scanf("%d %d", &a, &b);
        ans = pi*a + 2*b;
        ans -= 0.0000005;
        printf("%.6f\n", ans);
    }
    return 0;

 

你可能感兴趣的:(算法题目)