Line belt(三分镶嵌)
How long must he take to travel from A to D?
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
1
0 0 0 100
100 0 100 100
2 2 1
Sample Output
136.60 题目意思:就是给你两条线段AB , CD的坐标 ,一个人在AB以速度p跑,在CD上以q跑,在其他地方跑速度是r,问你从A到D最少的时间。
解题思路:设E在AB上,F在CD上。 则人在线段AB上花的时间为:f = AE / p
,人走完Z和Y所花的时间为:g= EF / r + FD / q
。
f函数是一个单调递增的函数,而g很明显是一个先递减后递增的函数。两个函数叠加,所得的函数应该也是一个先递减后递增的函数。这算是一道三分又三分的题目,可以看成是三分的镶嵌,
先对AB上的位置E进行三分枚举,每一次枚举的时候把E看做定点,在这种情况下,再对CD上的位置F进行三分枚举,这样可以求出此次三分AB的最小时间。然后完成对AB的三分后,就会得到从A到D的最短时间。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
#define EPS 1e-8
struct Point
{
double x;
double y;
} a, b, c, d, e, f;
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)///alpha代表在f点在cd中位置的比率
{
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;///返回在ef和fd上花费的时间
}
double inter_tri(double alpha)///在f点进行三分
{
double l = 0.0, r = 1.0, mid, mmid, cost;
e.x = a.x + (b.x - a.x) * alpha;
e.y = a.y + (b.y - a.y) * alpha;///e点在线段ab中的位置
while (r - l > EPS)
{
mid = (l + r) / ;
mmid = (mid + r) / ;
cost = calc(mid);
if (cost <= calc(mmid))
r = mmid;
else
l = mid;
}
return dis(a, e) / p + cost;
}
double solve()///在e点进行三分
{
double l = 0.0, r = 1.0, mid, mmid, ret;
while (r - l > EPS)
{
mid = (l + r) / ;
mmid = (mid + r) / ;
ret = inter_tri(mid);
if (ret <= inter_tri(mmid))
r = mmid;
else
l = mid;
}
return ret;
}
int main()
{
int T;
double ans;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);
scanf("%lf%lf%lf",&p,&q,&r);
ans=solve();
printf("%.2lf\n",ans);
}
return ;
}
Line belt(三分镶嵌)的更多相关文章
- 三分套三分 --- 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)To ...
- HDU 3400 Line belt (三分再三分)
HDU 3400 Line belt (三分再三分) ACM 题目地址: pid=3400" target="_blank" style="color:rgb ...
- 搜索(三分):HDU 3400 Line belt
Line belt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Line belt
Problem Description In a two-dimensional plane there are two line belts, there are two segments AB a ...
- HDU 3400 Line belt【三分套三分】
从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间 f = AE / p 在其他区域行走的时间 g = EF / r 在CD上行走的时间 ...
- HDU 3400 Line belt (三分套三分)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3400 题意: 有两条带子ab和cd,在ab上的速度为p,在cd上的速度为q,在其它地方的速度为r.现 ...
- hdu Line belt
这道题是一道3分搜索的题.其实这种题很多时候都出现在高中的解析几何上,思路很简单,从图中可以看到,肯定在AB线段和CD线段上各存在一点x和y使得所花时间最少 因为AB和CD上的时间与x和y点的坐标都存 ...
- hdu 3400 Line belt 三分法
思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段. 那么可以先三分得到AB上的一个点,在由这个点三分CD!! 代码如下: #include<iostr ...
随机推荐
- 557. Reverse Words in a String III (5月25日)
解答 class Solution { public: string reverseWords(string s) { string temp,result; while(1){ if(s.find( ...
- postman中 form-data、x-www-form-urlencoded、raw、binary的区别【转】
链接:https://blog.csdn.net/wangjun5159/article/details/47781443 1.form-data: 就是http请求中的multipart/form- ...
- 关于Hibernate基于version的乐观锁
刚刚接触SSH框架,虽然可能这个框架已经比较过时了,但是个人认为,SSH作为一个成熟的框架,作为框架的入门还是可以的. 马马虎虎学完了Hibernate的基础,总结一点心得之类的. 学习Hiberna ...
- css 自定义checkbox多选复选框样式
html: <input type="checkbox" id="" value="">菜单1 <input type=& ...
- java 整型数据转换为小数类型 BigDecimal 装换为Double
A,B为String类型 ,A-B=C BigDecimal A=(BigDecimal) map.get("A"); BigDecimal B=(BigDecimal) map. ...
- iOS 打包常见问题处理
Cannot proceed with delivery: an existing transporter instance is currently uploading this package 原 ...
- python+selenium webdriver.firefox()方式配置浏览器设置
webdriver.firefox() 爬虫需求: (其实是输入参数可获取.zip/pdf 文件,然后点击下载) ——但是firefox浏览器有Bug,点击下载之后会有弹出窗口,需要你点击确定,这怎 ...
- 爬虫-windows下安装Scrapy及scrapy模块介绍
一:安装wheel wheel介绍 二:安装twisted twisted是由python编写的一款基于事件驱动的网络引擎,使用twisted模块将python的异步请求(异步模型介绍)成为可能且简 ...
- 《TCP/IP详解 卷1:协议》第3章 IP:网际协议
3.1 引言 IP是TCP/IP协议族中最为核心的协议.所有的TCP.UDP.ICMP及IGMP数据都以IP数据报格式传输(见图1-4).许多刚开始接触TCP/IP的人对IP提供不可靠.无连接的数据报 ...
- linux 命令绿色安装
有些电脑不能联网,软件不能使用 apt-get 或 dnf . 从已安装的机器上拷贝命令到这台机器上就可以.设想. **** 以 tree 命令为例: **先从联网的机器上安装 apt-get ins ...