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,而 y y 的变化范围是[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

代码

#include <bits/stdc++.h>
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值