思路:要求最短时间从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. ASP.NET 之 常用类、方法的超级总结,并包含动态的EXCEL导入导出功能,奉上类库源码

    实用类:UtilityClass 包含如下方法 判断对象是否为空或NULL,如果是空或NULL返回true,否则返回false 验证手机号是否正确 13,15,18 验证邮箱 验证网址 MD5加密,返 ...

  2. 使用百度zrender, demo抛砖引玉.

    http://www.just.org.cn/zrender/index.html https://github.com/ecomfe/zrender 目录结构: |-project    |-dem ...

  3. linux环境下配置github远程仓库

    1.设置git用户和邮箱 git config --global user.name "fujinzhou" git config --global user.email &quo ...

  4. nand flash相关

    关于nandflash的说明,请参考其他. 现在先贴出来韦东山先生的代码,作我学习之用. @************************************************ @ Fil ...

  5. 【解惑】深入jar包:从jar包中读取资源文件

    [解惑]深入jar包:从jar包中读取资源文件 http://hxraid.iteye.com/blog/483115 TransferData组件的spring配置文件路径:/D:/develop/ ...

  6. ecshop中无限处理分类

    数据库表记录结构 <?php $sql = "SELECT c.cat_id, c.cat_name, c.measure_unit, c.parent_id, c.is_show, ...

  7. 一款js点击显示和隐藏的例子(pc,移动端通用)

    html部分: <div id="box"> <div id="box_title">标题</div> <div id ...

  8. js分割文件快速上传

    <?php header('Content-type:text/html;charset=UTF-8'); ?> <?php if ($_FILES) { if(!file_exis ...

  9. gson小练习之嵌套复杂数据解析

    package com.zf.demo; import java.util.List; import com.google.gson.Gson; public class JGson { /** * ...

  10. 在Linux环境下给php添加mbstring扩展

    1,今天在开发项目的时候使用了一个php函数(mb_strcut),运行代码时候提示报错"call to undefind function mb_strcut",首先检查下函数名 ...