标签:
三分套三分。。。其实直接看代码理解就可以了。
发现的新bug:(x,y,a,b)/p 这样的c++语句是合法的,我也不知道为什么,然后因为这一个我调了一节晚自修。。。药丸药丸!
#include<cstdio> #include<cstring> #include<cctype> #include<algorithm> #include<cmath> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define dwn(i,s,t) for(int i=s;i>=t;i--) #define clr(x,c) memset(x,c,sizeof(x)) int read(){ int x=0,f=1;char c=getchar(); while(!isdigit(c)) { if(c==‘-‘) f=-1;c=getchar(); } while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x*f; } const int inf=0x7f7f7f7f; const double eps=1e-3; double au,av,bu,bv,cu,cv,du,dv; double p,q,r; double dis(double a,double b,double x,double y){ return sqrt((x-a)*(x-a)+(y-b)*(y-b)); } double cal(double a,double b){ double la=cu,lb=cv,ra=du,rb=dv,xa,ya,xb,yb,ta,tb,orz,tmp; while(fabs(ra-la)>eps||fabs(rb-lb)>eps){ orz=(ra-la)/3;tmp=(rb-lb)/3; xa=orz+la,ya=tmp+lb; xb=orz*2+la,yb=tmp*2+lb; ta=dis(xa,ya,a,b)/r+dis(xa,ya,du,dv)/q; tb=dis(xb,yb,a,b)/r+dis(xb,yb,du,dv)/q; if(ta>tb) la=xa,lb=ya; else ra=xb,rb=yb; } return dis(au,av,a,b)/p+dis(la,lb,a,b)/r+dis(la,lb,du,dv)/q; } int main(){ au=read(),av=read(),bu=read(),bv=read(); cu=read(),cv=read(),du=read(),dv=read(); p=read(),q=read(),r=read(); double la=au,lb=av,ra=bu,rb=bv,xa,ya,xb,yb,ta,tb,orz,tmp; while(fabs(ra-la)>eps||fabs(rb-lb)>eps){ orz=(ra-la)/3;tmp=(rb-lb)/3; xa=orz+la,ya=tmp+lb; xb=orz*2+la,yb=tmp*2+lb; ta=cal(xa,ya);tb=cal(xb,yb); if(ta>tb) la=xa,lb=ya; else ra=xb,rb=yb; } printf("%.2lf\n",cal(la,lb)); return 0; } /* 0 0 0 100 100 0 100 100 2 2 1 */
对于100%的数据,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10
标签:
原文地址:http://www.cnblogs.com/fighting-to-the-end/p/5901521.html