oval-and-rectangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 237 Accepted Submission(s): 93
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.
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.
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.
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
Source
Recommend
题意:给你椭圆的短轴长和长轴长,求y=c和椭圆相交的点的矩形周长的期望
分析:首先根据题目给出的椭圆短轴长和长轴长可以得出椭圆的方程:x^2/a^2 + y^2/b^2
然后把y=c带进椭圆的方程可以求出对应的横坐标,矩形的周长即4*c+4*a*sqrt(1-c*c/b*b)
接着对椭圆的周长公式进行积分,注意我们求的是周长的期望所以积分的结果还要除以b(y可以取的最大值)
积分过程:
上面图片最后两行公式错了,应该是2b*b+π*a*b,最后除以b以后的期望是2*b+π*a
AC代码:
#pragma comment(linker, "/STACK:102400000,102400000") #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cassert> #include<string> #include<cstdio> #include<bitset> #include<vector> #include<cmath> #include<ctime> #include<stack> #include<queue> #include<deque> #include<list> #include<set> #include<map> using namespace std; #define debug test #define mst(ss,b) memset((ss),(b),sizeof(ss)) #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) #define ll long long #define ull unsigned long long #define pb push_back #define mp make_pair #define inf 0x3f3f3f3f #define eps 1e-10 typedef pair<int,int> PII; const ll mod = 1e9+7; const int N = 1e6+10; const double PI = acos(-1.0); ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qp(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} int to[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; int a,b,t; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>t; while(t--) { cin>>a>>b; double ans = 2.0*b+PI*a; ///double ans = 1.0*a*a+2.0*a/b*PI; ans = ans-5*1e-7; //严格控制在小数点后六位 printf("%.6lf\n",ans); ///printf("%.6lf\n",ans); } return 0; }