ZOJ 3203

虽然只是一道简单的三分

但是调的我要死

注意!!!!!

如果你的eps是1e-8,输出结果的时候一定要输出三分右端点所对应的值;

否则eps要调到1e-9;

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps=1e-9;
inline int read(){
	int x=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline double max(double x,double y){
	return x>y?x:y;
}
inline double cal_abs(double x){
	return max(x,-x);
}
inline int dcmp(double x,double y){
	double res=x-y;
	if(cal_abs(res)<eps) return 0;
	if(res<0) return -1;
	return 1;
}
int T;
double H,h,D;
inline double cal(double x){
	double y=D-x;
	double l1=(y/x)*(H-h);//x/(H-h)=y/suan
	return h-l1+y;
}
int main(){
	T=read();
	while(T--){
		scanf("%lf %lf %lf",&H,&h,&D);
		double l=D-D*h/H,r=D;
		while(dcmp(l,r)<0){
			double l1=(2*l+r)/3,r1=(l+2*r)/3;
			double ans1=cal(l1),ans2=cal(r1);
			int res=dcmp(ans1,ans2);
			if(res==1) r=r1;
			if(res==0) l=l1,r=r1;
			if(res==-1) l=l1;
			// cout<<l<<"\t"<<r<<endl;
		}
		printf("%.3lf\n",h-(H-h)*(D-l)/l+D-l);
	}
	return 0;
}

  

posted @ 2018-09-21 19:36  古城独钓  阅读(294)  评论(0)    收藏  举报