蛋疼的精度,蛋疼的多组数据。。
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #define eps 1e-9 6 double a,b; 7 double getsum(double c) 8 { 9 double p,sum = 0; 10 p = (a+b+c)/2; 11 sum += sqrt(p*(p-a)*(p-b)*(p-c)); 12 sum += c*c/4; 13 return sum; 14 } 15 int main() 16 { 17 double mid1,mid2,start,end,sq1,sq2; 18 while(scanf("%lf%lf",&a,&b)!=EOF) 19 { 20 start = 0; 21 end = a+b; 22 while(start+eps < end) 23 { 24 mid1 = (start+end)/2; 25 mid2 = (mid1+end)/2; 26 sq1 = getsum(mid1); 27 sq2 = getsum(mid2); 28 if(sq1 > sq2-eps) 29 end = mid2; 30 else 31 start = mid1; 32 } 33 printf("%.9lf\n",getsum(start)); 34 } 35 return 0; 36 }