XTU1175:Hurry Up(三分)

Problem Description

GG is some what afraid of his MM. Once his MM asks, he will always try his best to rush to their home.

Obvious, he can run home in straight line directly. Alternatively, he can run to the main road and call the taxi.

You can assume there is only one main road on the x-axis, with unlimited length.

Given the initial location of GG and his destination, please help to ask the minimize time to get home.

GG will always run at the fixed speed of vr, and the taxi can move at the fixed speed of vt

You can also assume that, only GG reach the main road, he can catch the taxi immediately. And the taxi will go towards home ( not necessay along the road ).

Bisides, GG can run arbitrary length, and pay arbitrarily for the taxi.

P.S. MM: abbr. Ma Ma

Input

Multiple test cases. First line, an integer T ( 1 ≤ T ≤ 2000 ), indicating the number of test cases.

For each test cases, there are 6 integers x1, y1, x2, y2, vr, vt in a line.

( -1000 <= x1, y1, x2, y2 <= 1000, 1 <= vr < vt <= 1000 )

(x1, y1) : the initial location of GG

(x2, y2) : the destination location of GG

vr: GG‘s run speed

vt: taxi‘s speed

Ouput

For each test case, output a real number with 2 digits after the arithmetic point. It is the shorest time for GG to reach home.

Sample Input

2
1 1 2 2 1 2
1 1 2 2 1 7

Sample Output

1.41
1.32

Source

XTU OnlineJudge

三分枚举答案。。。

坐的士的话,有两条路,一条是步行到X轴的时间,一段是X轴到家的时间,并且由于从左到有枚举X点的话,随着两段路长短的变化,时间也是递增的,所以可以进行三分

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

double x1,x2,yy1,yy2,vr,vt;

double dis(double x1,double y1,double x2,double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

double fun(double x)
{
    return dis(x1,yy1,x,0)/vr+dis(x2,yy2,x,0)/vt;
}

int main()
{
    int t;
    double t1,t2;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf%lf%lf",&x1,&yy1,&x2,&yy2,&vr,&vt);
        if(x1>x2) swap(x1,x2);
        t1 = dis(x1,yy1,x2,yy2)/vr;
        double l = x1,r = x2;
        while(r-l>1e-8)
        {
            double mid1 = (l+r)/2;
            double mid2 = (mid1+r)/2;
            if(fun(mid1)<fun(mid2)) r = mid2;
            else l = mid1;
        }
        printf("%.2f\n",t1<fun(l)?t1:fun(l));
    }

    return 0;
}

XTU1175:Hurry Up(三分),布布扣,bubuko.com

时间: 2024-08-06 13:09:31

XTU1175:Hurry Up(三分)的相关文章

2013湘潭赛

XTU1168 Alice and Bob 因为数据只有10000范围,直接递推就可以了 #include<stdio.h> #include<string.h> #include<vector> #include<list> #include<deque> #include<queue> #include<stack> #include<map> #include<set> #include<

XTU OJ 1175 Hurry Up(三分法&amp;&amp;穷举法)

 Hurry Up Accepted : 88   Submit : 345 Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description GG is some what afraid of his MM. Once his MM asks, he will always try his best to rush to their home. Obvious, he can run home in straight li

hdu 4717 The Moving Points(三分)

题目链接:hdu 4717 The Moving Points 题意: 在二维平面上有n个点,每个点给出移动的方向和速度. 问在某个时刻,这些点中最大距离最小是多少,输出时刻和距离. 题解: 我们可以知道,每个点对的距离要么是单调递增,要么是有一个峰的函数. 举例画一下可知道合成的这个函数最多只有一个峰,所以可以用三分求解. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespa

三分算法

三分算法 二分算法解决的是具有单调性的问题. 三分算法解决的是抛物线的类型,上凸,下凹. mid=(Left+Right)/2; midmid=(Right+mid)/2; 题目类型有: HDU :3400  2298  4454  2438  3756 POJ:  3301   3737 ZOJ: 3203

uvalive 4986(三分查找)

题意:空间内有n个点,求一个最小体积的圆锥把所有点包进去.输出圆锥的高和底面半径.圆锥的底面圆心在(0,0),所有点的z坐标都大于等于0. 题解:因为圆锥体积是 V = 1/3 * π * r^2 * h ,这是一个二次函数,也就是个凸性函数,可以用三分查找的方式枚举两个高,然后找到对应的最小的r,比对两个高得到的体积继续三分查找. #include <cstdio> #include <cstring> #include <algorithm> #include &l

Toxophily-数论以及二分三分

G - Toxophily Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2298 Description The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bridge, toxophily, deluxe ballroom

三分 --- CSU 1548: Design road

Design road Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到达(x,y).但是在0~x之间有n条平行于y轴的河,每条河位于xi处,无限长,wi宽,并分别给出了建立路和桥每公里的单价 求:到达目标的最小费用. analyse: 比赛的时候一直没想到思路,第二个样列怎么算都算不对,赛后才知道是三分. 首先把所有的桥移到最右端,然后三分枚举路和河的交点. Time

csu 1548: Design road (三分)

题意:需要从(0,0) 点 到(x,y) 修一段路 其中有n条和y轴平行的河 修路的单位成本c1 修桥的单位成本c2 问最小总成本为多少 思路:把所有河合并 再三分桥的长度 求出最小成本 #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queu

HDU 2438 Turn the corner (计算几何 + 三分)

Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2059    Accepted Submission(s): 785 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h