标签:isp include closed open amp src put tput double
对于100%的数据,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10
解:三分套三分;
#include<cstdio> #include<cstring> #include<cmath> using namespace std; const double eps=1e-3; double as(double a){if(a>=0) return a;return -a;} int xa,ya,xb,yb,xc,yc,xd,yd,p,q,r; inline double dis(double x1,double y1,double x2,double y2) { return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); } inline double get(double x,double y) { double lx=xc,ly=yc,rx=xd,ry=yd; double x1,x2,y1,y2,t1,t2; while(as(lx-rx)>eps||as(ly-ry)>eps) { x1=lx+(rx-lx)/3, y1=ly+(ry-ly)/3; x2=lx+(rx-lx)/3*2,y2=ly+(ry-ly)/3*2; t1=dis(xa,ya,x,y)/p+dis(x,y,x1,y1)/r+dis(x1,y1,xd,yd)/q; t2=dis(xa,ya,x,y)/p+dis(x,y,x2,y2)/r+dis(x2,y2,xd,yd)/q; if(t1>t2) lx=x1,ly=y1; else rx=x2,ry=y2; } return dis(xa,ya,x,y)/p+dis(x,y,lx,ly)/r+dis(lx,ly,xd,yd)/q; } int main() { scanf("%d %d %d %d %d %d %d %d %d %d %d",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd,&p,&q,&r); double lx=xa,ly=ya,rx=xb,ry=yb; double x1,x2,y1,y2,t1,t2; while(as(lx-rx)>eps||as(ly-ry)>eps) { x1=lx+(rx-lx)/3,y1=ly+(ry-ly)/3; x2=lx+(rx-lx)/3*2,y2=ly+(ry-ly)/3*2; t1=get(x1,y1),t2=get(x2,y2); if(t1>t2) lx=x1,ly=y1; else rx=x2,ry=y2; } printf("%.2lf",get(lx,ly)); return 0; }
=-=======================
标签:isp include closed open amp src put tput double
原文地址:http://www.cnblogs.com/12fs/p/7738932.html