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的上的点找到最优点,求距离 ...
随机推荐
- A glimpse of Support Vector Machine
支持向量机(support vector machine, 以下简称svm)是机器学习里的重要方法,特别适用于中小型样本.非线性.高维的分类和回归问题.本篇希望在正篇提供一个svm的简明阐述,附录则提 ...
- LuoguP1196_银河英雄传说_KEY
银河英雄传说 题目描述 公元5801年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历799年,银河系的两大军事集团在巴米利恩星域爆 ...
- Java 基础语法
一.关键字 定义:被 Java 赋予特殊含义的单词. 特点:基本上都是英文小写. 用于定义数据类型的关键字 基本数据类型 整数型(默认为 int) byte(8 位,1 字节,默认值是 0,最大存储数 ...
- CodeForces 242E二维线段树
E. XOR on Seg ...
- C++PrimerPlus第6版 第四章——复合类型
1,复合类型主要包含:数组.结构.联合.枚举.类.指针.引用等. 2,数组.长度必须确定.即编译阶段,数组的长度就得确定好.所以只能使用常量(#define.const)声明数组长度.如果使用变量声明 ...
- git-分支使用方式
需求场景:假如你看着教程完成了一个项目,但是感觉第一次代码掌握不牢,想要进行第二次代码练习--如果某某心里想我还有初始备份文件,我此时的心里独白是你的硬盘还够用吗o(╯□╰)o 1 创建一个新分支 - ...
- Echarts图表统计学习
史上最全的Echarts图表学习文档 http://echarts.baidu.com/doc/doc.html 勤加练习,多做总结! http://www.stepday.com/topic/?79 ...
- zabbix灵活使用userparameters
userparameters介绍 官网文献:https://www.zabbix.com/documentation/2.0/manual/config/items/userparameters 当我 ...
- 一些精妙的sql语句收集
--1.说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用) --法一: select * into b from a where 1<>1 --法二: select ...
- AspectCore中的IoC容器和依赖注入
IOC模式和依赖注入是近年来非常流行的一种模式,相信大家都不陌生了,在Asp.Net Core中提供了依赖注入作为内置的基础设施,如果仍不熟悉依赖注入的读者,可以看看由我们翻译的Asp.Net Cor ...
belt" title="Line belt">