oval-and-rectangle

 

oval-and-rectangle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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 < 10^5$). 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
 

分析:椭圆性质有:
将y=c带入,求出内接矩形的周长,通过积分求出答案。
ac代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int t;
 8     cin>>t;
 9     while(t--)
10     {
11         int a, b;
12         int x, y;
13         cin>>a>>b>>x>>y;
14         int w = b * (-1) * x / a;
15         printf("%d\n", x/(w-y));
16     }
17     return 0;
18 }
View Code

 

 

posted @ 2018-08-08 14:38  sqdtss  阅读(155)  评论(0编辑  收藏  举报