标签:csdn http lan comment clu targe ons blog 答案
算法模板:
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; }
----------------------------------------------------------------------------------------------------------
题目:ZOJ 3203
思路:推出公式,三分求答案,t代表人离墙角的距离
#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; }
标签:csdn http lan comment clu targe ons blog 答案
原文地址:https://www.cnblogs.com/tombraider-shadow/p/11221432.html