Description:
This requires an elliptical perimeter.
--------------------------------------
Question:
1. Point + longberger point acceleration (my method and code are relatively long)
After reading this question, I am an evil Baidu Algorithm for calculating the elliptical perimeter. Obtain an integral formula.
However, this question requires a high accuracy, at least six digits after the decimal point. In this way, the ds value is very small, which makes the program use tle.
At this point, my mind flashed through the point acceleration in numerical analysis.
So I flipped through the courseware and found out the lenberger formula .. (I have discovered the important role of the computing method)
2. (For details about the code, refer to the Code to be explored)
--------------------------------------
Question details:
I learned several methods of pi:
1. pi = acos (-1.0)
2. pi = (4.0 * atan (1.0 ))
(The principles of this method are to be explored)
--------------------------------------
Source code 1:
[Cpp]
# Include <iostream>
# Include <stdio. h>
# Include <math. h>
Using namespace std;
# Define Pi 3.1415926535898
# Define ds 0.0000005
# Define M 40
Double a = 0, B = 0;
Double f (double si)
{
Return sqrt (1-(a * a-B * B)/(a * a) * sin (si ));
}
Long Sq (int k)
{
Long m = 1;
For (; k> 0; k --)
M * = 2;
Return m;
}
Double rom (double a, double B, double e)
{
Double T [M], S [M], C [M], R [M], y;
Int k = 0, I;
Double h = (B-a) * 1.0;
T [1] = h/2.0 * (f (a) + f (B ));
H/= 2.0;
For (k = 1; k <= M; k ++, h/= 2)
{
Y = 0;
For (I = 1; I <= Sq (k-1); I ++)
{
Y + = f (a + (2 * i-1) * h );
}
T [Sq (k)] = T [Sq (k-1)]/2.0 + h * y;
S [Sq (k-1)] = 4.0/3 * T [Sq (k)]-1.0/3 * T [Sq (k-1)];
If (K-2> = 0)
C [Sq (K-2)] = 16.0/15 * S [Sq (k-1)]-1.0/15 * S [Sq (K-2)];
If (K-3> = 0)
R [Sq (K-3)] = 64.0/63 * C [Sq (K-2)]-1.0/63 * C [Sq (K-3)];
If (K-4> = 0 ){
If (fabs (R [Sq (K-3)]-R [Sq (K-4)]) <e)
Break ;}
}
Return R [Sq (K-3)];
}
Int main ()
{
Int t = 0, k = 0;
Double ans = 0;
Scanf ("% d", & t );
For (k = 1; k <= t; k ++)
{
Scanf ("% lf", & B, & );
Ans = 4 * a * rom (Pi/2, 0, ds );
Printf ("Case % d: %. 6lf \ n", k, fabs (ans ));
}
Return 0;
}
Source code 2:
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Include <math. h>
Const double pi = (4.0 * atan (1.0 ));
Double a, B; www.2cto.com
Int main (){
Int I, j, T, cas = 0;
Scanf ("% d", & T );
While (T --){
Scanf ("% lf", & B, & );
Double e = 1.0-(B * B)/(a * );
Double sum = 1.0, tmp = 1.0;
For (I = 1; I <100000; I ++ ){
Double r = (2.0 * i-1)/(2.0 * I );
Sum-= (tmp * = r * e)/(2.0 * i-1 );
}
Printf ("Case % d: %. 8f \ n", ++ cas, 2.0 * pi * a * sum );
}
Return 0;
}