HDU3400+三分

把a,d这两个起点和终点之间的中间点三分出来。

其他没什么。

/*
两次三分
题意:给定abcd四个点(包括速度,位置),从a到d,求最短时间。
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxn = 105;
const double eps = 1e-8;
const double pi = acos(-1.0);
struct Point {
	double x,y;
};
Point a,b,c,d;
double P,Q,R,ans1,ans2;

double dis( Point aa,Point bb ){
	return sqrt( (aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y) );
}

double GetAns( double tt1,double tt2 ){
	double ans;
	Point temp1,temp2;
	temp1.x = a.x+tt1*(b.x-a.x),temp1.y = a.y+tt1*(b.y-a.y);
	temp2.x = c.x+tt2*(d.x-c.x),temp2.y = c.y+tt2*(d.y-c.y);
	ans = dis( a,temp1 )/P+dis( temp1,temp2 )/R+dis( temp2,d )/Q;
	return ans;
}

double solve( double x ){
	double L,R,mid1,mid2;
	L = 0;
	R = 1;
	while( R-L>eps ){
		mid1 = (L+R)/2.0;
		mid2 = (mid1+R)/2.0;
		
		if( GetAns( x,mid1 )<GetAns( x,mid2 ) ){
			ans2 = mid1;
			R = mid2;
		}
		else{
			ans2 = mid2;
			L = mid1;
		}
	}
	return GetAns( x,ans2 );
}

int main(){
	int T;
	scanf("%d",&T);
	while( T-- ){
		scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
		scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);
		scanf("%lf%lf%lf",&P,&Q,&R);
		double L,R,mid1,mid2;
		L = 0;
		R = 1;
		while( R-L>eps ){
			mid1 = (L+R)/2.0;
			mid2 = (mid1+R)/2.0;
			
			if( solve( mid1 )<solve( mid2 ) ){
				ans1 = mid1;
				R = mid2;
			}
			else{
				ans1 = mid2;
				L = mid1;
			}
		}
		printf("%.2lf\n",GetAns( ans1,ans2 ));
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值