标签:led 2.0 rmi scan 数据 col cal stream ring
对于100%的数据,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000。1<=P,Q,R<=10
设(A,B)上有一点E,(C,D)上有一点F,那么最优方案肯定是A->E->F->D。发现E和F的位置是两个单峰函数,然后三分套个三分就可以过了_(:зゝ∠)_
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<cmath> 6 using namespace std; 7 8 int Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,P,Q,R; 9 double eps=1e-8; 10 11 double cost(double x,double y,double p,double q,double v) 12 { 13 return sqrt((p-x)*(p-x)+(q-y)*(q-y))/v; 14 } 15 16 double calc(double x,double y,double p,double q) 17 { 18 return cost(Ax,Ay,x,y,P)+cost(x,y,p,q,R)+cost(p,q,Dx,Dy,Q); 19 } 20 21 double work2(double x,double y) 22 { 23 double lx=Cx,ly=Cy,rx=Dx,ry=Dy; 24 double lmidx,rmidx,lmidy,rmidy,ans1,ans2; 25 while(fabs(rx-lx)>eps || fabs(ry-ly)>eps) 26 { 27 lmidx=lx+(rx-lx)/3.0; 28 rmidx=lx+((rx-lx)/3.0)*2.0; 29 lmidy=ly+(ry-ly)/3.0; 30 rmidy=ly+((ry-ly)/3.0)*2.0; 31 ans1=calc(x,y,lmidx,lmidy); 32 ans2=calc(x,y,rmidx,rmidy); 33 if(ans1>ans2)lx=lmidx,ly=lmidy; 34 else rx=rmidx,ry=rmidy; 35 } 36 return (max(calc(x,y,lx,ly),calc(x,y,rx,ry))); 37 } 38 39 double work1() 40 { 41 double lx=Ax,ly=Ay,rx=Bx,ry=By; 42 double lmidx,rmidx,lmidy,rmidy,ans1,ans2; 43 while(fabs(rx-lx)>eps || fabs(ry-ly)>eps) 44 { 45 lmidx=lx+(rx-lx)/3.0; 46 rmidx=lx+((rx-lx)/3.0)*2.0; 47 lmidy=ly+(ry-ly)/3.0; 48 rmidy=ly+((ry-ly)/3.0)*2.0; 49 ans1=work2(lmidx,lmidy); 50 ans2=work2(rmidx,rmidy); 51 if(ans1>ans2)lx=lmidx,ly=lmidy; 52 else rx=rmidx,ry=rmidy; 53 } 54 return (max(work2(lx,ly),work2(rx,ry))); 55 } 56 57 int main() 58 { 59 scanf("%d%d%d%d",&Ax,&Ay,&Bx,&By); 60 scanf("%d%d%d%d",&Cx,&Cy,&Dx,&Dy); 61 scanf("%d%d%d",&P,&Q,&R); 62 printf("%.2lf\n",work1()); 63 }
标签:led 2.0 rmi scan 数据 col cal stream ring
原文地址:https://www.cnblogs.com/refun/p/9627756.html