zoukankan      html  css  js  c++  java
  • hdoj_3400Line belt

    Line belt

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1885    Accepted Submission(s): 713


    Problem Description
    In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's speed on AB is P and on CD is Q, he can move with the speed R on other area on the plane.
    How long must he take to travel from A to D?
     

    Input
    The first line is the case number T.
    For each case, there are three lines.
    The first line, four integers, the coordinates of A and B: Ax Ay Bx By.
    The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.
    The third line, three integers, P Q R.
    0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
    1<=P,Q,R<=10
     

    Output
    The minimum time to travel from A to D, round to two decimals.
     

    Sample Input
    1 0 0 0 100 100 0 100 100 2 2 1
     

    Sample Output
    136.60
     
    三分嵌套三分。
    AB上确定一点,然后三分枚举CD上的点。
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    const double EPS = 1e-10;
    
    int p,q,r;
    
    struct point {
    	double x;
    	double y;
    };
    
    double dis(point a,point b)
    {
    	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    
    double findy(point c,point d,point y)
    {
    	point mid,midmid,left,right;
    	double mid_t,midmid_t;
    	left = c;
    	right = d;
    	do
    	{
    		mid.x = (left.x + right.x) / 2;
    		mid.y = (left.y + right.y) / 2;
    		midmid.x = (right.x + mid.x) / 2;
    		midmid.y = (right.y + mid.y) / 2;
    		mid_t = dis(d,mid) / q + dis(mid,y) / r;
    		midmid_t = dis(d,midmid) / q+dis(midmid,y) / r;
    		if(mid_t > midmid_t)
    			left = mid;
    		else right = midmid;
    	}while(fabs(mid_t - midmid_t)>EPS);
    	return mid_t;
    }
    double find(point a,point b,point c,point d)
    {
    	point mid,midmid,left,right;
    	double mid_t,midmid_t;
    	left = a;
    	right = b;
    	do
    	{
    		mid.x = (left.x + right.x) / 2;
    		mid.y = (left.y + right.y) / 2;
    		midmid.x = (right.x + mid.x) / 2;
    		midmid.y = (right.y + mid.y) / 2;
    		mid_t = dis(a,mid) / p + findy(c,d,mid);
    		midmid_t = dis(a,midmid) / p + findy(c,d,midmid);
    		if(mid_t > midmid_t)left = mid;
    		else right = midmid;
    	}while(fabs(mid_t - midmid_t)>EPS);
    	return mid_t;
    }
    
    int main()
    {
    	freopen("in.txt","r",stdin);
    	int t;
    	point a,b,c,d;
    	cin>>t;
    	while(t--)
    	{
    		cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y;
    		cin>>p>>q>>r;
    		printf("%.2lf\n",find(a,b,c,d));
    	}
    	
    	return 0;
    }


  • 相关阅读:
    [Docker][ansible-playbook]3 持续集成环境之分布式部署
    [Jenkins][GitHub]2 持续集成环境初探
    [Jenkins][centos]1 持续集成 之 配置VNC,部署Jenkins
    [AWS][GUI][VNC]rhel 7 安装GUI ,配置VNC
    [Git]checkout 指定版本
    [Golang][Mac]Go 语言学习资料记录
    App测试札记
    摘记:代码检查错误列表
    摘记:Web应用系统测试内容
    摘记:LoadRunner
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835342.html
Copyright © 2011-2022 走看看