3
5
2016
0

[BZOJ1857] [Scoi2010]传送带

三分点在AB和CD上面的位置

然后搞一搞就行了

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
friend Point operator+(Point a,Point b){return Point(a.x+b.x,a.y+b.y);}
friend Point operator-(Point a,Point b){return Point(a.x-b.x,a.y-b.y);}
friend Point operator*(Point a,double k){return Point(a.x*k,a.y*k);}
double mold(){return sqrt(x*x+y*y);}
}A,B,C,D;

double V0,Vab,Vcd;
const double eps=1e-6;

double Calc(Point X,Point Y){
return (Y-X).mold()/V0+(Y-D).mold()/Vcd;
}

double sanfen2(Point x){
double l=0,r=1,res=(x-A).mold()/Vab;
while(r-l>eps){
	double mid1=l+(r-l)/3.0,mid2=r-(r-l)/3.0;
	double p1=Calc(x,C+(D-C)*mid1),p2=Calc(x,C+(D-C)*mid2);
	if(p1<p2)r=mid2;
	else l=mid1;
}
return res+Calc(x,C+(D-C)*l);
}

double sanfen1(){
double l=0,r=1;
while(r-l>eps){
	double mid1=l+(r-l)/3.0,mid2=r-(r-l)/3.0;
	double p1=sanfen2(A+(B-A)*mid1),p2=sanfen2(A+(B-A)*mid2);
	if(p1<p2)r=mid2;
	else l=mid1;
}
return sanfen2(A+(B-A)*l);
}

int main(){
freopen("1857.in","r",stdin);
freopen("1857.out","w",stdout);
scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y);
scanf("%lf %lf %lf",&Vab,&Vcd,&V0);
printf("%.2lf\n",sanfen1());
return 0;
}
Category: BZOJ | Tags: OI bzoj | Read Count: 361

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com