好玩的题。ABCD四点,三分法嵌套三分法。看代码应该更清晰一点~
#include#include using namespace std;const double eps=1e-7;double p,q,r;struct Point{ double x,y;} A,B,C,D;double getDistance(Point a,Point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double cToD(Point a){ Point midl,midr; Point left=C,right=D; while(fabs(left.x-right.x)>eps||fabs(left.y-right.y)>eps) { midl.x=(right.x+left.x*2)/3; midl.y=(right.y+left.y*2)/3; midr.x=(right.x*2+left.x)/3; midr.y=(right.y*2+left.y)/3; if(getDistance(a,midl)/r+getDistance(D,midl)/q eps||fabs(left.y-right.y)>eps) { midl.x=(right.x+left.x*2)/3; midl.y=(right.y+left.y*2)/3; midr.x=(right.x*2+left.x)/3; midr.y=(right.y*2+left.y)/3; if(getDistance(A,midl)/p+cToD(midl) >cas; while(cas--) { cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y>>p>>q>>r; printf("%.2lf\n",aToD()); }}