标签:
#include<cmath> #include<cstdio> #include<algorithm> using namespace std; int read_p,read_ca,read_f; inline int read(){ read_p=0;read_ca=getchar();read_f=1; while(read_ca<‘0‘||read_ca>‘9‘) {if (read_ca==‘-‘) read_f=-1;read_ca=getchar();} while(read_ca>=‘0‘&&read_ca<=‘9‘) read_p=read_p*10+read_ca-48,read_ca=getchar(); return read_p*read_f; } int xa,ya,xb,yb,xc,yc,xd,yd,p,q,r; long double z1,z2; inline double g(double a,double b){ double xx1,yy1,xx2,yy2,zz1,zz2; zz1=a/z1;zz2=b/z2; xx1=xa+(xb-xa)*zz1; yy1=ya+(yb-ya)*zz1; xx2=xd+(xc-xd)*zz2; yy2=yd+(yc-yd)*zz2; return a/p+b/q+sqrt((xx2-xx1)*(xx2-xx1)+(yy2-yy1)*(yy2-yy1))/r; } inline double f(double x){ double l=0,r=z2,mid1,mid2,w; while (r-l>=1e-10){ w=(r-l)/3.0;mid1=l+w;mid2=mid1+w; if (g(x,mid1)>g(x,mid2)) l=mid1;else r=mid2; } return g(x,l); } int main(){ /*freopen("a.in","r",stdin); freopen("a.out","w",stdout);*/ xa=read();ya=read();xb=read();yb=read();xc=read();yc=read();xd=read();yd=read(); z1=sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));z2=sqrt((xd-xc)*(xd-xc)+(yd-yc)*(yd-yc)); p=read();q=read();r=read(); double l=0,r=z1,mid1,mid2,w; while (r-l>1e-10){ w=(r-l)/3.0;mid1=l+w;mid2=mid1+w; if (f(mid1)>f(mid2)) l=mid1;else r=mid2; } printf("%.2lf\n",f(l)); }
标签:
原文地址:http://www.cnblogs.com/Enceladus/p/5346413.html