Computational Geometry - chipping the maximum volume of circular table

Topic links: http://codeforces.com/gym/100796/problem/I

Ideas: the use of oblique truncated cone is tangent to the sphere and determines whether or not the ball is tangent to the trapezoidal waist binary search can be performed in the front view.

AC Code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const double eps = 1e-8;
 4 bool check(double h,double r, double R,double m)
 5 {
 6     double af = atan(h/(R-r));
 7     double bt = atan(m/R);
 8     double gm = af - bt;
 9     double ans = sqrt(m*m+R*R) * sin(gm);
10     return ans - m >= eps;
11 }
12 int main()
13 {
14     double R,r,h;
15     scanf("%lf %lf %lf",&r,&R,&h);
16     double ll = 0, rr = h / 2.0;
17     while(rr - ll >= eps)
18     {
19         double mid = (ll + rr)/2;
20         if(check(h,r,R,mid)) ll = mid;
21         else rr = mid;
22     }
23     printf("%.12f",ll);
24     return 0;
25 }

 

Guess you like

Origin www.cnblogs.com/Carered/p/11318281.html