oval-and-rectangle

oval-and-rectangle

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在x軸上。
半短軸長度爲b在y軸上。
在y軸上從[0,b]區間中隨機選擇一個實數c,經過點(0,c)做一條垂直於y軸的直線,進而得到一個矩形:
1。它的四個頂點在橢圓的輪廓上。
2。它的兩邊平行於座標軸。
3。它的一邊是y=c。
求矩形周長的期望值。

思路

首先由題意我們可以畫出一個圖
這裏寫圖片描述

那麼很顯然我們要求周長的期望,就要對周長進行積分再除以積分區間即可

這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述

代碼
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define LL long long
#define inf 0x3f3f3f3
const int mod = 1e9+7;
const int N = 1e5+7;
int main ()
{
    int t;
    double a,b,ans;
    scanf("%d",&t);
    while (t--)
    {
        scanf("%lf %lf",&a,&b);
        ans = a*PI+2*b-0.0000005;
        printf("%.6f\n",ans);
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章