HDU 6362 oval-and-rectangle(圆锥曲线+积分+函数期望)

版权声明: https://blog.csdn.net/Adusts/article/details/81904812

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<b<a<105 ). Separated by an white space.

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的值,接着有一条直线y=c与椭圆相交,以此确定四个点,需要你求以这四个点为顶点的矩形的周长的期望。

#include <cstdio>
#include <cmath>
#include <iostream>
#define PI acos(-1)
using namespace std;
int main() {
	int t, a, b;
	scanf("%d", &t);
	while(t--) {
        scanf("%d %d", &a, &b);
        double ans = PI*a + 2*b;
        ans -= 0.0000005;
        printf("%lf\n", ans);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Adusts/article/details/81904812
今日推荐