HDU6362 oval-and-rectangle(2018HDU多校联赛第六场,数学,积分)

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 a , b 已知)

做法是先把椭圆的周长加起来再除以变化范围。

比如这个图,我们知道焦点在 x x 轴的椭圆的公式为 x2a2+y2b2=1 x 2 a 2 + y 2 b 2 = 1 ,而 y y 的变化范围是 [0,b] [ 0 , b ] ,那么由公式变形可以知道:

x2=a2(1y2b2) x 2 = a 2 ∗ ( 1 − y 2 b 2 )

x=a1y2b2 x = a 1 − y 2 b 2

然后就可以知道椭圆上的点的坐标为 (a1y2b2,y) ( a 1 − y 2 b 2 , y )

那么周长为:

C=4(x+y)=4y+4a1y2b2 C = 4 ( x + y ) = 4 y + 4 a 1 − y 2 b 2

然后就需要求出积分:

by=0(4y+4a1y2b2)dy ∫ y = 0 b ( 4 ∗ y + 4 a ∗ 1 − y 2 b 2 ) d y

换元,设 y=bsin(α) y = b s i n ( α ) , dy=bcos(α)dα d y = b c o s ( α ) d α .

原式 =1/2πα=0(4bsin(α)+4acos(α))bcos(α)dα = ∫ α = 0 1 / 2 π ( 4 b ∗ s i n ( α ) + 4 a ∗ c o s ( α ) ) b c o s ( α ) d α

=1/2πα=0(2b2sin(2α)+2ab(cos(2α)+1))dα = ∫ α = 0 1 / 2 π ( 2 b 2 ∗ s i n ( 2 α ) + 2 a b ∗ ( c o s ( 2 α ) + 1 ) ) d α

=[b2cos(2α)+ab(sin(2α)+2α)]1/2π0 = [ − b 2 c o s ( 2 α ) + a b ( s i n ( 2 α ) + 2 α ) ] 0 1 / 2 π

=[b2+πab][b2] = [ b 2 + π a b ] − [ − b 2 ]

=2b2+πab = 2 b 2 + π a b

因为变化范围是 [0,b] [ 0 , b ] ,所以最后算期望除以 b b

=2b+πa = 2 b + π a

代码

#include 
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
const double pi=acos(-1.0);
const int N=1e5+10;
void solve()
{
    double a,b;
    scanf("%lf%lf",&a,&b);
    double ans=2*b+pi*a;
    printf("%.6f\n",ans-0.0000005);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}

你可能感兴趣的:(【概率,期望,物理】,【多校联赛】,积分)