hdu 3400 Line belt 三分
题意:已知在线段AB上的速度是p,在CD上的速度是q,在其他地方的速度是r,求A到D的最短时间
思路:三分AB上一点,根据这点三分CD
#include <iostream> #include <algorithm> #include <string.h> #include <stdio.h> #include <vector> #include <queue> #include <math.h> using namespace std; #define LL long long #define eps 1e-6 #define maxn 300 struct point { double x,y; point() { } point(double xx,double yy) { x=xx; y=yy; } } p[5]; double dist(point a,point b) { return hypot(fabs(a.x-b.x),fabs(a.y-b.y)); } double P,Q,R; double solve(point c,point d,point x) { point mid1,mid2,left,right; double t1=0,t2=1; left=c; right=d; while(fabs(t1-t2)>eps) { mid1=point((left.x+right.x)/2,(left.y+right.y)/2); mid2=point((right.x+mid1.x)/2,(right.y+mid1.y)/2); t1=dist(d,mid1)/Q+dist(x,mid1)/R; t2=dist(d,mid2)/Q+dist(x,mid2)/R; if(t1>t2) left=mid1; else right=mid2; } return t1; } int main() { int T,i; scanf("%d",&T); while(T--) { for(i=0; i<4; i++) scanf("%lf%lf",&p[i].x,&p[i].y); scanf("%lf%lf%lf",&P,&Q,&R); point mid1,mid2,left,right; double t1=0,t2=1; left=p[0]; right=p[1]; while(fabs(t1-t2)>eps) { mid1=point((left.x+right.x)/2,(left.y+right.y)/2); mid2=point((right.x+mid1.x)/2,(right.y+mid1.y)/2); t1=dist(p[0],mid1)/P+solve(p[2],p[3],mid1); t2=dist(p[0],mid2)/P+solve(p[2],p[3],mid2); if(t1>t2) left=mid1; else right=mid2; } printf("%.2f\n",t1); } return 0; }