1 条题解
-
0
C++ :
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> using namespace std; #define eps 1e-3 double ax,ay,bx,by,cx,cy,dx,dy,p,q,r; inline int read(){ int x=0,t=1,c; while(!isdigit(c=getchar())) if(c=='-') t=-1; while(isdigit(c)) x=x*10+c-'0',c=getchar(); return x*t; } double dis(double x1,double y1,double x2,double y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));} double calc(double x,double y){ double lx=cx,ly=cy,rx=dx,ry=dy; while(fabs(rx-lx)>eps || fabs(ry-ly)>eps){ double x1=lx+(rx-lx)/3.0,y1=ly+(ry-ly)/3.0; double x2=rx-(rx-lx)/3.0,y2=ry-(ry-ly)/3.0; double t1=dis(ax,ay,x,y)/p+dis(x,y,x1,y1)/r+dis(x1,y1,dx,dy)/q; double t2=dis(ax,ay,x,y)/p+dis(x,y,x2,y2)/r+dis(x2,y2,dx,dy)/q; if(t1>t2) lx=x1,ly=y1; else rx=x2,ry=y2; } return dis(ax,ay,x,y)/p+dis(x,y,lx,ly)/r+dis(lx,ly,dx,dy)/q; } void sanfen(){ double lx=ax,ly=ay,rx=bx,ry=by; while(fabs(rx-lx)>eps || fabs(ry-ly)>eps){ double x1=lx+(rx-lx)/3.0,y1=ly+(ry-ly)/3.0; double x2=rx-(rx-lx)/3.0,y2=ry-(ry-ly)/3.0; double t1=calc(x1,y1),t2=calc(x2,y2); if(t1>t2) lx=x1,ly=y1; else rx=x2,ry=y2; } printf("%.2lf",calc(lx,ly)); } int main(){ scanf("%lf%lf%lf%lf",&ax,&ay,&bx,&by); scanf("%lf%lf%lf%lf",&cx,&cy,&dx,&dy); scanf("%lf%lf%lf",&p,&q,&r); sanfen(); return 0; }
- 1
信息
- ID
- 1059
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 2
- 上传者