Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 455 Accepted Submission(s): 203
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
题意:求椭圆内接矩形的周长的期望
解析:
其实就是让求均值,把所有可能周长加起来除去变化范围即可
首先要求出周长公式
我们知道椭圆的公式为
这样我们知道y的变化范围是[0,b][0,b],并且我们可以求出x用y表示
因此可以得到周长公式
因为我们要求所有可能周长之和因此实际上就是求周长的黎曼和即求周长公式的积分
我们当时做的时候就求到这里的,然后直接用辛普森求积分的近似公式直接做了,样例过提交死活不对,我们知道肯定是精度问题,然后又手动求导,得到式子,还是不行,就死活用三角函数代换,哎没办法基础知识不牢固,高数都忘了,反正还是太菜了
因此周长和为因为变化范围是0-b
所以再除以b便是期望
所以最终只需求一个式子
2b+a
因为题目要求保留6位小数,并且后面的全部舍去,因此为了防止%.6f造成四舍五入,因此给答案-0.0000005
#include
using namespace std;
#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
int T;
scanf("%d",&T);
while(T--)
{
double a,b;
scanf("%lf%lf",&a,&b);
double ans = 2 * b + pi * a ;
printf("%.6f\n",ans-0.0000005);
}
return 0;
}