oval-and-rectangle(橢圓與矩形)
題目連結
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 :
-
The four vertexes of it are on the outline of the oval.
-
The two sides of it parallel to coordinate axis.
-
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),需要求出橢圓內接矩形的周長的期望。
看到這裡,一個數學小菜雞掉下了悔恨的眼淚…
高數真滴菜…
在圖中,有
+
=1,而y的變化範圍是[0,b];
則公式可變換為:
x=a
所以,周長為:
C=4(x+y)=4y+4a
然後就需要求出積分:
結果為
=2
+
ab
然後除以b以後,結果就是
=2b+
a
然後加到程式碼裡面求解即可:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double Pi=acos(-1.0);///emmmm,就是pai嘛....
void perimeter()
{
double a,b;
scanf("%lf%lf",&a,&b);
double ans=2*b+Pi*a;///也就是剛剛那個公式
printf("%.6f\n",ans-0.0000005);///不讓進位,進位結果會錯的
}
int main()
{
int t;
cin >> t;
while(t--)
perimeter();
return 0;
}
GG