标签:efi abs 技术 clu 分享 sqrt 这一 str src
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<cstdlib> #define eps 1e-3 using namespace std; struct point { int x,y; }a,b,c,d; int p,q,r; double dis(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double cal(double x,double y) { double lx=c.x,ly=c.y,rx=d.x,ry=d.y; double x1,y1,x2,y2,t1,t2; double ab=dis(x,y,a.x,a.y)/p; while(fabs(rx-lx)>eps||fabs(ry-ly)>eps) { x1=lx+(rx-lx)/3;y1=ly+(ry-ly)/3; x2=lx+(rx-lx)/3*2;y2=ly+(ry-ly)/3*2; t1=ab+dis(x1,y1,x,y)/r+dis(d.x,d.y,x1,y1)/q; t2=ab+dis(x2,y2,x,y)/r+dis(d.x,d.y,x2,y2)/q; if(t1>t2)lx=x1,ly=y1; else rx=x2,ry=y2; } return ab+dis(lx,ly,x,y)/r+dis(d.x,d.y,lx,ly)/q; } int read() { int x=0,f=1;char 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; } int main() { a.x=read();a.y=read();b.x=read();b.y=read(); c.x=read();c.y=read();d.x=read();d.y=read(); p=read();q=read();r=read(); double lx=a.x,ly=a.y,rx=b.x,ry=b.y; double x1,y1,x2,y2,t1,t2; while(fabs(rx-lx)>eps||fabs(ry-ly)>eps) { x1=lx+(rx-lx)/3;y1=ly+(ry-ly)/3; x2=lx+(rx-lx)/3*2;y2=ly+(ry-ly)/3*2; t1=cal(x1,y1);t2=cal(x2,y2); if(t1>t2)lx=x1,ly=y1; else rx=x2,ry=y2; } printf("%.2lf",cal(lx,ly)); return 0; }
标签:efi abs 技术 clu 分享 sqrt 这一 str src
原文地址:http://www.cnblogs.com/JKAI/p/6925759.html