| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:请教zoj 2614,Bridge.30th ICPC杭州.做过的请问有什么陷阱啊,是不是直接解方程?In Reply To:请教zoj 2614,Bridge.30th ICPC杭州.做过的请问有什么陷阱啊,是不是直接解方程? Posted by:majia001 at 2006-07-14 20:53:34 附WA源码
#include<stdio.h>
#include<math.h>
double d,l,h;
double f(double t){
double y1,s;
y1=d*sqrt((t*2/d)*(t*2/d)+1)/2;
s=2*t/d;//以下防止实数相除失去精度
if(s>1e-7)return y1+log(sqrt(s*s+1)+s)*d/(2*s)-l;
else return y1+d/2-l;
}
double bin(double a,double b){//二分法解f(x)=0
if(fabs(b-a)<1e-4)return (a+b)/2;
else if(f(a)*f((a+b)/2)<0)return bin(a,(a+b)/2);
else return bin((a+b)/2,b);
}
main(){
int t,j;
double b,ans,i;
scanf("%d",&t);
for(j=1;j<=t;j++){
scanf("%lf%lf%lf%lf",&d,&h,&b,&l);
if(fabs(b-l)<1){ans=0;goto l1;}
for(i=1;b/i>d;i++);
d=b/(i*2);l=l/(i*2);
ans=bin(0,h);//显然f(0)>0,f(h<0),此区间可以用二分
l1: printf("case %d:\n",j);
printf("%.2f\n",h-ans);
if(j!=t)printf("\n");
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator