bzoj 1857 传送带
题目大意:
在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段
两条传送带分别为线段AB和线段CD
在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R
从A点走到D点,最少需要走多长时间
思路:
两个三分套起来搞
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstdlib> 5 #include<cstring> 6 #include<algorithm> 7 #include<vector> 8 #include<queue> 9 #define inf 2139062143 10 #define ll long long 11 #define MAXN 100100 12 #define eps 1e-3 13 using namespace std; 14 inline int read() 15 { 16 int x=0,f=1;char ch=getchar(); 17 while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();} 18 while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();} 19 return x*f; 20 } 21 int x[5],y[5],p,q,r; 22 double dis(double x1,double y1,double x2,double y2) {return hypot(fabs(y1-y2),fabs(x1-x2));} 23 double gets(double x1,double y1,double x2,double y2) {return dis(x[1],y[1],x1,y1)/p+dis(x1,y1,x2,y2)/r+dis(x2,y2,x[4],y[4])/q;} 24 double calc(double kx,double ky) 25 { 26 double lx=x[3],ly=y[3],rx=x[4],ry=y[4],mlx,mrx,mly,mry; 27 while(fabs(rx-lx)>eps||fabs(ry-ly)>eps) 28 { 29 mlx=lx+(rx-lx)/3,mly=ly+(ry-ly)/3; 30 mrx=lx+(rx-lx)/3*2,mry=ly+(ry-ly)/3*2; 31 //cout<<kx<<" "<<ky<<" "<<lx<<" "<<ly<<" "<<rx<<" "<<ry<<endl; 32 //cout<<" "<<mlx<<" "<<mly<<" "<<mrx<<" "<<mry<<endl; 33 if(gets(kx,ky,mlx,mly)>gets(kx,ky,mrx,mry)) lx=mlx,ly=mly; 34 else rx=mrx,ry=mry; 35 } 36 return gets(kx,ky,lx,ly); 37 } 38 int main() 39 { 40 for(int i=1;i<=4;i++) x[i]=read(),y[i]=read(); 41 p=read(),q=read(),r=read(); 42 double lx=x[1],ly=y[1],rx=x[2],ry=y[2],mlx,mrx,mly,mry; 43 while(fabs(rx-lx)>eps||fabs(ry-ly)>eps) 44 { 45 //cout<<lx<<" "<<ly<<" "<<rx<<" "<<ry<<endl; 46 mlx=lx+(rx-lx)/3,mly=ly+(ry-ly)/3; 47 mrx=lx+(rx-lx)/3*2,mry=ly+(ry-ly)/3*2; 48 if(calc(mlx,mly)>calc(mrx,mry)) lx=mlx,ly=mly; 49 else rx=mrx,ry=mry; 50 } 51 printf("%.2lf\n",calc(lx,ly)); 52 }