HDU 3400 Line belt【三分套三分】
从A出发到D,必定有从AB某个点E出发,从某个点F进入CD
故有E,F两个不确定的值。
在AB上行走的时间 f = AE / p
在其他区域行走的时间 g = EF / r
在CD上行走的时间 h = FD / q
总时间 T = f + g + h
当E确定时,T1 = g + h + C 此时g时一个先减后增的凹函数,h是一个单调递减的凹函数,根据凹函数的性质,故T1是一个凹函数
反之亦然,故需要三分确定其中一个点的位置,再三分另一个点的位置。
#include<stdio.h>
#include<string.h>
#include<math.h>
const double eps=1e-;
struct node{
double x,y;
}a,b,c,d,e,f;
double p,q,r;
double dis(node A,node B){
double x=A.x-B.x;
double y=A.y-B.y;
return sqrt(x*x+y*y);
}
double cal(double bi){
f.x=c.x+(d.x-c.x)*bi;
f.y=c.y+(d.y-c.y)*bi;
return dis(e,f)/r+dis(f,d)/q;
}
double find2(double bi){
e.x=a.x+(b.x-a.x)*bi;
e.y=a.y+(b.y-a.y)*bi;
double l=,r=,mid,mmid;
while(r-l>eps){
mid=(l+r)/;
mmid=(mid+r)/;
if(cal(mid)<cal(mmid))
r=mmid;
else
l=mid;
}
return cal(l)+dis(a,e)/p;
}
double find1(){
double l=,r=,mid,mmid;
while(r-l>eps){
mid=(l+r)/;
mmid=(mid+r)/;
if(find2(mid)<find2(mmid))
r=mmid;
else
l=mid;
}
return find2(l);
}
int main(){
int t;
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);
printf("%.2f\n",find1());
}
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)To ...
- 搜索(三分):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 (三分套三分)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3400 题意: 有两条带子ab和cd,在ab上的速度为p,在cd上的速度为q,在其它地方的速度为r.现 ...
- hdu 3400 Line belt 三分法
思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段. 那么可以先三分得到AB上的一个点,在由这个点三分CD!! 代码如下: #include<iostr ...
- hdu 3400 Line belt
题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...
- BZOJ 1857 传送带 (三分套三分)
在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从 ...
- 【BZOJ-1857】传送带 三分套三分
1857: [Scoi2010]传送带 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1077 Solved: 575[Submit][Status][ ...
随机推荐
- 使用Apache ab进行压力测试(参数说明)
我们一般会使用Apache自带的ab来对项目进行压力测试,看项目的执行情况如何. 我们可以使用 ab -v 来查看ab的详细参数使用方法. [root@node234 bin]# ./ab -v ab ...
- ng-show
//当ng-show="false"时,自动添加 #animate.ng-hide { } #animate.ng-hide-add { } #animate.ng-hide-ad ...
- ABAP中Conversion Routine示例
在SAP的Domain定义中,Output Length下面有个Convers. routine的标识,这是SAP用来进行输入输出转换的.我们知道,屏幕上的I/O字段都是字符串形式的,而数 ...
- Office 365 - Windows PowerShell for SharePoint Online
Office 365 PowerShell for SharePoint Online 1. Get-SPOTenantLogEntry 并不能获取所有的Log信息,只能用于获取因外部资源而出错的lo ...
- SharePoint2013 - 移动文档
In SharePoint 2010, the easiest way to transfer documents from one library to another involved using ...
- UDF2
问题 根据给定的gps点point(x,y)和北京的shape数据,关联出 AOI ID IO 输入 gps点表 create table gps ( x double, //经度 y double ...
- Android 在外部存储读写文件
本文主要介绍android中如何在外部存储读写数据 sd卡的路径 sdcard:2.3之前的sd卡路径 mnt/sdcard:4.3之前的sd卡路径 storage/sdcard:4.3之后的sd卡路 ...
- iOS--APP 登录界面图(xuer)
ViewController.h #import "ViewController.h" @interface ViewController () @property(strong, ...
- 手动删除webapps下项目,导致Document base %TOMCAT_HOME%\webapps\XXX does not exist or is not a readable directory
删除 %TOMCAT_HOME%\conf\XXX.xml , 再次eclipse中重新启动tomcat,错误就会消失.
- Linux学习书目
Linux基础 1.<Linux与Unix Shell 编程指南> C语言基础 1.<C Primer Plus,5th Edition>[美]Stephen Prata著 2 ...