很简单的一题,注意墙上的影子是放大就行。用三分。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
double H,h,D;
double cal(double x){
return x+(h-x/D*H)*D/(D-x);
}
int main(){
double ans; int T;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf",&H,&h,&D);
ans=h/H*D;
double l=0,r=ans;
double m,mm;
while(l+(1e-8)<r){
m=l+(r-l)/3;
mm=r-(r-l)/3;
if(cal(m)>cal(mm))
r=mm;
else l=m;
}
ans=max(ans,cal(l));
printf("%.3lf\n",ans);
}
return 0;
}
原文:http://www.cnblogs.com/jie-dcai/p/4276035.html