Line belt
two-dimensional plane there are two line belts, there are two
segments AB and CD, lxhgww's speed on AB is P and on CD is Q, he
can move with the speed R on other area on the plane.
How long must he take to travel from A to D?
is the case number T.
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
time to travel from A to D, round to two decimals.
100
100
1
#include
#include
#include
#include
using namespace std;
const double eps=1e-6;
struct coordinate
{
double
x;
double
y;
};
coordinate A,B,C,D;
int t;
double p,q,r;
double dis(coordinate a,coordinate b)
{
double
t;
t=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
//printf("t=%.2f\n",t);
return
t;
}//求两点之间的距离
coordinate midc(coordinate a,coordinate b)
{
coordinate
t;
t.x=(a.x+b.x)*0.5;
t.y=(a.y+b.y)*0.5;
return
t;
}//求坐标的中点
double time(coordinate a,coordinate b,coordinate c,coordinate
d)
{
double
t;
t=dis(a,b)/p+dis(b,c)/r+dis(c,d)/q;
//printf("t=%.2f\n",t);
return
t;
}//求路径的总时间
double Three_algorithm_1(coordinate a,coordinate c,coordinate
d)
{
double
t1,t2;
coordinate
left,right,mid,midmid;
left=c;
right=d;
do
{
mid=midc(left,right);
midmid=midc(mid,right);
// printf("dis(right,left)=%.5f\n",dis(right,left));
t1=dis(a,mid)/r+dis(mid,d)/q;
t2=dis(a,midmid)/r+dis(midmid,d)/q;
if(t1>t2)left=mid;
else right=midmid;
}while(dis(right,left)>=eps);
return
t1;
}//先求出A到CD段的最小时间
double Three_algorithm_2(coordinate a,coordinate b,coordinate
c,coordinate d)
{
double
t1,t2;
coordinate
left,right,mid,midmid;
left=a;
right=b;
mid=midc(left,right);
midmid=midc(mid,right);
do
{
mid=midc(left,right);
midmid=midc(mid,right);
//printf("dis(right,left)=%.f\n",dis(right,left));
t1=dis(a,mid)/p+Three_algorithm_1(mid,c,d);
t2=dis(a,midmid)/p+Three_algorithm_1(midmid,c,d);
if(t1>t2)left=mid;
else right=midmid;
}while(dis(right,left)>=eps);
return
t1;
}//加上前面求出的先求出A到CD段的最小时间,用三分求最少时间
int main()
{
//freopen("in.txt", "r", stdin);
scanf("%d",&t);
for(int
i=0;i
{
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("%.2lf\n",Three_algorithm_2(A,B,C,D));
}
}
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)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 (三分再三分)
HDU 3400 Line belt (三分再三分) ACM 题目地址: pid=3400" target="_blank" style="color:rgb ...
- Line belt(三分镶嵌)
In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's spee ...
- HDU 3400 Line belt【三分套三分】
从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间 f = AE / p 在其他区域行走的时间 g = EF / r 在CD上行走的时间 ...
- 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 ...
- hdu 3400 Line belt
题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...
随机推荐
- Rendering Problems Failed to load platform rendering library 为何打开布局页面时手机预览页面显示不出来?
看到图片右上角的 android图标没有?把它改为低版本的就可以了,如我的是21就可以了.原因我想是因为sdk版本更新了不兼容导致的吧.
- angular directive自定义指令
先来看一下自定义指令的写法 app.directive('', ['', function(){ // Runs during compile return { // name: '', // pri ...
- 个人从源码理解JIT模式下angular编译AppModule的过程
承接上文.笔者之前将一个angular项目的启动过程分为了两步: 创建平台得到 PlatformRef ,以及执行平台引用提供的方法编译根模块 AppModule .本文就将着眼于创建好的平台,从an ...
- php中常用的字符串查找函数strstr()、strpos()实例解释
string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] ) 1.$haystack被查找的字 ...
- 从入门到精通之Boyer-Moore字符串搜索算法详解
本文讲述的是Boyer-Moore算法,Boyer-Moore算法作为字符串搜索算法,兴趣之下就想了解这个算法,发现这个算法一开始还挺难理解的,也许是我理解能力不是很好吧,花了小半天才看懂,看懂了过后 ...
- FPGA与数字信号处理
过去十几年,通信与多媒体技术的快速发展极大地扩展了数字信号处理(DSP)的应用范围.眼下正在发生的是,以更高的速度和更低的成本实现越来越复杂的算法,这是针对高级信息服更高带宽以及增强的多媒体处理能力等 ...
- ZOJ1181 Word Amalgamation 字符串 排序查找
传送门:ZOJ1181 思路:自身排序来判断两个字符串拥有相同的字符. #include<cstdio> #include<cstdlib> #include<io ...
- zoj1383 zoj3418 二进制 基础
传送门 题目大意:从末位到首位输出所在位置的值是1的位置. 可以用除----> num>>1 或减----> -(n^(-n)) #include<cstdio> ...
- JS里try...catch...finally详解,以及console日志调试(console.log、console.info等)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- C#钩子类 几乎捕获键盘鼠标所有事件
using System; using System.Text; using System.Runtime.InteropServices; using System.Reflection; usin ...
belt" title="Line belt">