joj 2346

这是一个数学问题求近似值


 #include <stdio.h>

  #include <math.h>
  #define PI acos(-1.0)
  #define B 1e-8
  double cmp, area, a, b;
  double getb(double ta){
  double b = sqrt(1.0 - ta * ta);
  double sja = ta * b;
  double temp = asin(ta) - sja;
 return temp / (area - temp);
}
 int main(){
 //freopen("2346.in", "r", stdin);
 //freopen("2346.out", "w", stdout);
 double begin, end, mid, bi, temp;
 int i, j;
 while(scanf("%lf%lf", &a, &b) != -1){
    begin = 0.0;end = 2.0;area = PI;
    if(a > b) bi = b / a;
    else bi = a / b;
    while(1){
     mid = (begin + end) * 0.5;
    temp = getb(mid * 0.5);
     if(fabs(temp - bi) < B)break;
     else if(temp < bi)begin = mid;
     else end = mid;
    }
    printf("%.4lf\n", mid);
 }
 return 0;
 }
 
 

你可能感兴趣的:(joj 2346)