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的上的点找到最优点,求距离 ...
随机推荐
- oracle 例外
一.例外分类oracle将例外分为预定义例外.非预定义例外和自定义例外三种.1).预定义例外用于处理常见的oracle错误.2).非预定义例外用于处理预定义例外不能处理的例外.3).自定义例外用于处理 ...
- Android在 普通类(非Activity,多数为Adapter) 中 传输数据为空值 解决方法 :在startActivity 用 intent传输数据
这是bundle是传输不了数据的,获取到 出现这种情况的原因是非activity类中不存在Context,而在活动中传输数据时需要Context. 我收集到了两种解决方法. 1. 在调用该Adapte ...
- Vue状态管理vuex
前面的话 由于多个状态分散的跨越在许多组件和交互间各个角落,大型应用复杂度也经常逐渐增长.为了解决这个问题,Vue提供了vuex.本文将详细介绍Vue状态管理vuex 引入 当访问数据对象时,一个 V ...
- bzoj3209 花神的数论题 (二进制数位dp)
二进制数位dp,就是把原本的数字转化成二进制而以,原来是10进制,现在是二进制来做,没有想像的那么难 不知到自己怎么相出来的...感觉,如果没有一个明确的思路,就算做出来了,也并不能锻炼自己的能力,因 ...
- 一文为你详细讲解对象映射库【AutoMapper】所支持场景
前言 在AutoMapper未出世前,对象与对象之间的映射,我们只能通过手动为每个属性一一赋值,时间长了不仅是我们而且老外也觉得映射代码很无聊啊.这个时候老外的所写的强大映射库AutoMapper横空 ...
- Angular - 预加载 Angular 模块
Angular - 预加载延迟模块 在使用路由延迟加载中,我们介绍了如何使用模块来拆分应用,在访问到这个模块的时候, Angular 加载这个模块.但这需要一点时间.在用户第一次点击的时候,会有一点延 ...
- ZOJ3508 The War 贪心,最大流
传送门:I Am Here 常规解法是贪心,但是在复习最大流的写法,因此用sap来写的.思路是很好想的 #include<cstdio> #include<cstdlib> # ...
- c# Socket通讯中关于粘包,半包的处理,加分割符
using System; using System.Collections.Generic; using System.Text; using System.Net.Sockets; using S ...
- 项目常见函数封装,基于Jquery
/// <reference path="jquery-1.8.0.min.js" /> /* * DIV或元素居中 * @return */ jQuery.fn.mC ...
- Django入门教程(二)
建议直接阅读末尾!!! Writing your first Django app, part 2 本节将设置数据库,创建您的第一个模型(model),并简单介绍Django自动生成的管理页面. 数据 ...
belt" title="Line belt">