hdu 3400

Line belt

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


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
 

Author
lxhgww&&momodi
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   2199  2899  2298  2289  1551 



先三分AB上的点,再三分CD上的点即可。 
证明: 
设E在AB上,F在CD上。 
令人在线段AB上花的时间为: f = AE / p ,人走完Z和Y所花的时间为: g = EF / r + FD / q 。 



#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;


#define pi acos(-1)
#define endl '\n'
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0);
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,-1,-1,1,1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e5+100;
const double EPS=1e-7;
const int MOD=1000000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;
/*lch[root] = build(L1,p-1,L2+1,L2+cnt);
    rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*/
/*lch[root] = build(L1,p-1,L2,L2+cnt-1);
    rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/
long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}

inline int Scan()
{
    int res=0,ch,flag=0;
    if((ch=getchar())=='-')flag=1;
    else if(ch>='0' && ch<='9')res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';
    return flag ? -res : res;
}
struct Point
{
    double x;
    double y;
} a, b, c, d, e, f;

int t;
double p, q, r;

double dis(Point p1, Point p2)
{
    return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
double calc(double alpha)
{
    f.x = c.x + (d.x - c.x) * alpha;
    f.y = c.y + (d.y - c.y) * alpha;
    return dis(f, d) / q + dis(e, f) / r;
}
double inter_tri(double alpha)
{
    e.x = a.x + (b.x - a.x) * alpha;
    e.y = a.y + (b.y - a.y) * alpha;
    double l = 0.0, r = 1.0, mid, mmid, cost;
    while (r - l > EPS)
    {
        mid = (l + r) / 2;
        mmid = (mid + r) / 2;
        cost = calc(mid);
        if (cost <= calc(mmid))
            r = mmid;
        else
            l = mid;
    }
    return dis(a, e) / p + cost;
}
double solve()
{
    double l = 0.0, r = 1.0, mid, mmid, ret;
    while (r - l > EPS)
    {
        mid = l+(r-l)/3;
        mmid =  r-(r-l)/3;  //三分模版
        ret = inter_tri(mid);  //两次三分
        if (ret <= inter_tri(mmid))
            r = mmid;
        else
            l = mid;
    }
    return ret;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin >> a.x >> a.y >> b.x >> b.y;
        cin >> c.x >> c.y >> d.x >> d.y;
        cin >> p >> q >> r;
        printf("%.2f\n", solve());
    }
}







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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值