思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段。

那么可以先三分得到AB上的一个点,在由这个点三分CD!!

代码如下:

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
double P,Q,R,ab,cd;
struct point
{
double x,y;
}an[],pp,qq;
int n;
double dis(point &a,point &b)
{
return sqrt(1e-+(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));//注意这里要加上1e-5
}
double cal2(double t)
{
qq.x=an[].x+(an[].x-an[].x)/cd*t*Q;
qq.y=an[].y+(an[].y-an[].y)/cd*t*Q;
return dis(pp,qq)/R+t;
}
double cal(double t)
{
double l,r,mid,mmid,ans;
pp.x=an[].x+(an[].x-an[].x)/ab*t*P;
pp.y=an[].y+(an[].y-an[].y)/ab*t*P;
l=0.0;r=cd/Q;
while((1e-+l)<r){
mid=(r+l)/;
mmid=(mid+r)/;
ans=cal2(mid);
if((ans+1e-)<cal2(mmid))
r=mmid;
else l=mid;
}
return ans+t;
}
int main(){
int t,i;
double l,r,mid,mmid,ans;
cin>>t;
while(t--){
for(i=;i<;i++)
cin>>an[i].x>>an[i].y;
cin>>P>>Q>>R;
ab=dis(an[],an[]);
cd=dis(an[],an[]);
l=0.0;r=ab/P;
while((1e-+l)<r){
mid=(r+l)/;
mmid=(mid+r)/;
ans=cal(mid);
if((ans+1e-)<cal(mmid))
r=mmid;
else l=mid;
}
printf("%.2lf\n",ans);
}
return ;
}

hdu 3400 Line belt 三分法的更多相关文章

  1. HDU 3400 Line belt (三分再三分)

    HDU 3400 Line belt (三分再三分) ACM 题目地址:  pid=3400" target="_blank" style="color:rgb ...

  2. 三分套三分 --- HDU 3400 Line belt

    Line belt Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3400 Mean: 给出两条平行的线段AB, CD,然后一 ...

  3. 搜索(三分):HDU 3400 Line belt

    Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. HDU 3400 Line belt (三分嵌套)

    题目链接 Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. HDU 3400 Line belt (三分套三分)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3400 题意: 有两条带子ab和cd,在ab上的速度为p,在cd上的速度为q,在其它地方的速度为r.现 ...

  6. HDU 3400 Line belt【三分套三分】

    从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间   f = AE / p 在其他区域行走的时间 g = EF / r 在CD上行走的时间   ...

  7. hdu 3400 Line belt

    题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...

  8. 【HDOJ】3400 Line belt

    三分. #include <cstdio> #include <cstring> #include <cmath> typedef struct { double ...

  9. Line belt

    Problem Description In a two-dimensional plane there are two line belts, there are two segments AB a ...

随机推荐

  1. 有趣的hello word

    程序一 #define _________ } #define ________ putchar #define _______ main #define _(a) ________(a); #def ...

  2. SVN Application

    一.SVN客户端:TortoiseSvn 下载地址: http://tortoisesvn.net/downloads.html 安装完后重启, 右击就可以使用SVN命令 首先, 从服务器版本库那边 ...

  3. iOS - 视图与手势(UIview & UIGestureRecognizer)

    01 UIView视图的基本使用 --- 在根视图中添加2个UIView视图 //视图确实加载时调用 - (void)viewDidLoad { [super viewDidLoad]; // Do ...

  4. Html.ActionLink 几种重载方式说明及例子

    本文整理了该方法的几种重载形式:一 Html.ActionLink("linkText","actionName")该重载的第一个参数是该链接要显示的文字,第二 ...

  5. ArrayList和Array之间的转换

    ArrayList转Array (1):使用ArrayList的toArray方法.     1)当ArrayList中存放的是引用类型时(例如String),成功     /**      * 使用 ...

  6. 暑假集训(4)第七弹——— 组合(hdu1850)

    题意概括:你赢得了第一局.魔鬼给出的第二局是,如果有N堆牌,先手的人有几种可能胜利. 问题分析:尼姆游戏,先得到n堆牌的数量异或和,再将异或和与每一个牌组的数量异或,如果结果小于原牌组数量 则可能++ ...

  7. python pil 安装

    Ubuntu下 sudo pip install pil 安装PIL可能会出现问题,例如安装完成时显示JPEG support not available 或者 ZLIB (PNG/ZIP) supp ...

  8. linux网络编程九:splice函数,高效的零拷贝

    from:http://blog.csdn.net/jasonliuvip/article/details/22600569 linux网络编程九:splice函数,高效的零拷贝 最近在看<Li ...

  9. Asp.Net Web API VS Asp.Net MVC

    http://www.dotnet-tricks.com/Tutorial/webapi/Y95G050413-Difference-between-ASP.NET-MVC-and-ASP.NET-W ...

  10. mysql ab 压力测试的解读(转)

    本文转自:http://www.cnblogs.com/lemtree/articles/1676641.html. 就是APACHE自带的测试工具AB(apache benchmark).在APAC ...