hdu 3400 Line belt 三分法
思路:要求最短时间从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 三分法的更多相关文章
- HDU 3400 Line belt (三分再三分)
HDU 3400 Line belt (三分再三分) ACM 题目地址: pid=3400" target="_blank" style="color:rgb ...
- 三分套三分 --- HDU 3400 Line belt
Line belt Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3400 Mean: 给出两条平行的线段AB, CD,然后一 ...
- 搜索(三分):HDU 3400 Line belt
Line belt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 3400 Line belt (三分嵌套)
题目链接 Line belt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 3400 Line belt (三分套三分)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3400 题意: 有两条带子ab和cd,在ab上的速度为p,在cd上的速度为q,在其它地方的速度为r.现 ...
- HDU 3400 Line belt【三分套三分】
从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间 f = AE / p 在其他区域行走的时间 g = EF / r 在CD上行走的时间 ...
- hdu 3400 Line belt
题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...
- 【HDOJ】3400 Line belt
三分. #include <cstdio> #include <cstring> #include <cmath> typedef struct { double ...
- Line belt
Problem Description In a two-dimensional plane there are two line belts, there are two segments AB a ...
随机推荐
- JAVA中RSS解析器(rome.jar和jdom.jar)范例
1.需要 jdom.jar 和 rome.jar 这两个包.2.创建一个项目,web.xml的内容如下: 代码如下 复制代码 <?xml version="1.0" enco ...
- Linux 最常用命令小结
1. 文件共享 1).将windows 系统下的文件夹共享到linux的方法: 安装filezilla,设置连接linux 服务器.将文件上传. 2).mRemote 机器连接管理 2. 文件管理命令 ...
- Cocos中的观察者设计模式与通知机制
观察者(Observer)模式也叫发布/订阅(Publish/Subscribe)模式,是 MVC( 模型-视图-控制器)模式的重要组成部分.天气一直是英国人喜欢讨论的话题,而最近几年天气的变化也成为 ...
- C#学习笔记之线程 - 同步上下文
同步上下文(Synchronization Contexts) 手动使用锁的一个替代方案是去声明锁.通过派生ContextBoundObject和应用Synchronization属性,你告诉CLR自 ...
- 致vi老大 2011.1
文/安然 亲爱的,你即将离去 飞机起飞的一刻, 请珍藏起我们2010的回忆 桃源仙谷,曾留下我们踏青的足迹 难忘,石头上小憩 小北门外,我们在大排档里尽情欢喜 见证,杯盘狼藉 饺子店,是冬日里四面八方 ...
- IPointCollection转IPolyline
IPointCollection转线IPolyline: IPolyline pl = new PolylineClass(); IPointCollection ptc = pl as IPoint ...
- C# 导出 Excel
/// <summary> /// 导出Excel /// </summary> public void ExportExcel() { #region 添加引用 Micros ...
- SQL Server数据库连接类SQLHelper.cs
using System; using System.Collections.Generic; using System.Text; using System.Configuration; using ...
- 弹性布局学习-详解align-content(六)
弹性布局学习-详解align-content(六)
- 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 ...