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
思路
留下了数学渣的泪水…
题目给了一个椭圆,然后让你求内接矩形的周长的期望,(已知)
做法是先把椭圆的周长加起来再除以变化范围。
比如这个图,我们知道焦点在轴的椭圆的公式为,而的变化范围是,那么由公式变形可以知道:
然后就可以知道椭圆上的点的坐标为
那么周长为:
然后就需要求出积分:
换元,设, .
原式
因为变化范围是,所以最后算期望除以 。
代码
#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;
}
上一篇: php 对输入信息的进行安全过滤的函数代码_PHP教程
下一篇: msp430实现串口计算器