Thirds -zoj3203

Thirds:    https://blog.csdn.net/pi9nc/article/details/9666627#commentBox

Algorithms template:

while(l+esp<=r)
        {
            double mid=(l+r)/2;
            double midmid=(r+mid)/2;
            double ans1=cal(mid);
            double ans=cal(midmid);
            if(ans1>=ans) r=midmid;
            else l=mid; 
        }

----------------------------------------------------------------------------------------------------------

Topic: ZOJ 3203

Ideas: the introduction of a formula, one-third seek answers, t representative of the distance from the corner

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
//double X1, Y1, x2, y2, vx1, vy1, vx2, vy2;
//double pow2(double x) { return x * x; }
const double esp=1e-6;
double H,h,D;
double cal(double t)
{
  return D-t+H-(H-h)*D/t;    
} 
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>H>>h>>D;
        double l=D-h*D/H;
        double r=D;
        while(l+esp<=r)
        {
            double mid=(l+r)/2;
            double midmid=(r+mid)/2;
            double ans1=cal(mid);
            double ans=cal(midmid);
            if(ans1>=ans) r=midmid;
            else l=mid; 
        }
        printf("%.3lf\n",cal(r));
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/tombraider-shadow/p/11221432.html
ZOJ