题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1857
三分套三分。
#include<cstring> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstdio> #include<cmath> #include<queue> #define rep(i,l,r) for (int i=l;i<=r;i++) #define down(i,l,r) for (int i=l;i>=r;i--) #define clr(x,y) memset(x,y,sizeof(x)) #define maxn 100500 #define eps 1e-3 #define ll long long using namespace std; double ax,ay,bx,by,cx,cy,dx,dy,p,q,r; int read(){ int x=0,f=1; char ch=getchar(); while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();} return x*f; } double sqr(double x){ return x*x; } double dis(double x,double y,double xx,double yy){ return sqrt(sqr(x-xx)+sqr(y-yy)); } double cal(double x,double y){ double lx=cx,ly=cy,rx=dx,ry=dy; while (fabs(lx-rx)>=eps||fabs(ly-ry)>=eps){ double mx=(rx-lx)/3,my=(ry-ly)/3; double t1=dis(ax,ay,x,y)/p+dis(x,y,lx+mx,ly+my)/r+dis(lx+mx,ly+my,dx,dy)/q; double t2=dis(ax,ay,x,y)/p+dis(x,y,lx+mx*2,ly+my*2)/r+dis(lx+mx*2,ly+my*2,dx,dy)/q; if (t1<t2) {rx=lx+mx*2,ry=ly+my*2;} else {lx=lx+mx; ly=ly+my;} } return dis(ax,ay,x,y)/p+dis(x,y,lx,ly)/r+dis(lx,ly,dx,dy)/q; } 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); double lx=ax,ly=ay,rx=bx,ry=by; while (fabs(lx-rx)>=eps||fabs(ly-ry)>=eps){ double mx=(rx-lx)/3,my=(ry-ly)/3; double t1=cal(lx+mx,ly+my),t2=cal(lx+mx*2,ly+my*2); if (t1<t2) {rx=lx+mx*2,ry=ly+my*2;} else {lx=lx+mx; ly=ly+my;} } printf("%.2lf ",cal(lx,ly)); return 0; }