题目链接:

题目

B. Chip 'n Dale Rescue Rangers

time limit per test:1 second

memory limit per test:256 megabytes

问题描述

A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road.

We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2).

Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed meters per second.

Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after seconds the new position of the dirigible will be .

Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer.

It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air.

输入

The first line of the input contains four integers x1, y1, x2, y2 (|x1|,  |y1|,  |x2|,  |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively.

The second line contains two integers and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively.

Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that and .

输出

Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

样例

input

0 0 5 5

3 2

-1 -1

-1 0

output

3.729935587093555327

题意

救援飞船在(x1,y1)点,遇难者在(x2,y2)点,在前t秒时间里刮一号风:(vx,vy),在之后的时间里刮二号风(wx,wy),你飞船的最大速度为v,v大于风的速度。问你飞船能够到达遇难者的最短的时间。

题解

首先,如果给我们的时间越多,我们就越能够接近飞船!(一个特殊情况就是把飞船的前进方向控制在直线上。)也就是说,时间在可达和不可达的问题上是单调的!,我们可以对时间进行二分!求出最小的可行解!

那么要怎么判断给定的时间t,飞船能不能到达遇难者的位置呢?

其实只要给定固定的时间,我们的最优行路线是固定的!

速度是可以叠加的,我们可以考虑在t秒的时间,只有风的作用下的情况,我们会从(x1,y1)到达(x1+tvx,y1+tvy),记为(xm,ym),接下来再考虑没有风的情况下用速度v是否能从(xm,ym)到达(xt,yt)就可以了,即判断v*t>=dis((xm,ym)->(xt,yt))是否成立;

那么有两段风怎么办?

我们可以考虑先判断一下t秒这个时间是否可以到达,如果可以,那我们二分的范围就是(0,t),且只要考虑第一个风。 如果不可以,就二分(t,INF),且两个风都要考虑(利用叠加的原理,其实和 上面一种情况没什么差。)。

代码

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std; typedef __int64 LL;
int xs,ys,xt,yt,v,t,vx,vy,wx,wy;
const int INF=0x3f3f3f3f;
const int TIM=1000;
const double eps=1e-8; int Scan(){ int x; scanf("%d",&x); return x; } void input(){
xs=Scan(); ys=Scan();
xt=Scan(); yt=Scan();
v=Scan(); t=Scan();
vx=Scan(); vy=Scan();
wx=Scan(); wy=Scan();
} int main(){
input();
double xm=xs+vx*t,ym=ys+vy*t;
double dis=sqrt((xt-xm)*(xt-xm)+(yt-ym)*(yt-ym));
if(1.0*v*t>=dis+eps){
double l=0,r=t;
while(r-l>eps){
double mid=l+(r-l)/2;
double _xm=xs+vx*mid,_ym=ys+vy*mid;
double _dis=sqrt((xt-_xm)*(xt-_xm)+(yt-_ym)*(yt-_ym));
if(1.0*v*mid>=_dis+eps) r=mid;
else l=mid;
}
printf("%.18lf\n",r);
}else{
double l=0,r=INF;
while(r-l>eps){
double mid=l+(r-l)/2;
double _xm=xm+wx*mid,_ym=ym+wy*mid;
double _dis=sqrt((xt-_xm)*(xt-_xm)+(yt-_ym)*(yt-_ym));
if(1.0*v*(mid+t)>=_dis+eps) r=mid;
else l=mid;
}
printf("%.18lf\n",r+t);
}
return 0;
}

Codeforces Round #327 (Div. 1) B. Chip 'n Dale Rescue Rangers 二分的更多相关文章

  1. Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers 二分 物理

    D. Chip 'n Dale Rescue Rangers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  2. codeforces 590B B. Chip 'n Dale Rescue Rangers(二分+计算几何)

    题目链接: B. Chip 'n Dale Rescue Rangers time limit per test 1 second memory limit per test 256 megabyte ...

  3. cf590B Chip 'n Dale Rescue Rangers

    B. Chip 'n Dale Rescue Rangers time limit per test 1 second memory limit per test 256 megabytes inpu ...

  4. codeforces590b//Chip 'n Dale Rescue Rangers//Codeforces Round #327 (Div. 1)

    题意:从一点到另一点,前t秒的风向与t秒后风向不同,问到另一点的最短时间 挺难的,做不出来,又参考了别人的代码.先得到终点指向起点的向量,设T秒钟能到.如果T>t则受风1作用t秒,风2作用T-t ...

  5. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  6. Codeforces Round #327 (Div. 2) E. Three States BFS

    E. Three States Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/probl ...

  7. Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律

    C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...

  8. Codeforces Round #327 (Div. 2) B. Rebranding 水题

    B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...

  9. Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing

    http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...

随机推荐

  1. linux 用户打开进程数和文件数调整

    1 查看nproc(max user processes)命令 [root@vm-cdh4 ~]# ulimit -u 14866 2 修改nproc 临时修改, 重登录或重启后失效: [root@v ...

  2. Java关键字介绍之this与super

    1.什么是super?什么是this? super关键字表示超(父)类的意思.this变量代表对象本身. 2.使用super&this调用成员变量和方法 可以使用super访问父类被子类隐藏的 ...

  3. floodfill算法解题示例

    Flood fill算法是从一个区域中提取若干个连通的点与其他相邻区域区分开(或分别染成不同颜色)的经典算法.因为其思路类似洪水从一个区域扩散到所有能到达的区域而得名.在GNU Go和扫雷中,Floo ...

  4. oracle11.0.2 64位版本 Toad连接

    今天重装了系统 oracle  oracle客户端 之前连不上toad 今天总结 客户端路径:E:\app\ruonanxiao-pc\product\11.2.0\client_1 服务端路径:E: ...

  5. 使用C++读取UTF8及GBK系列的文本方法及原理

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4374404.html 1.读取UTF-8编码文本原理 首先了解UTF-8的编码方式,UTF- ...

  6. ubuntu下安装 Source insight

    习惯了在source insight下编辑阅读源码,在linux下用vi总是用不好 ,还是在ubuntu上用回熟悉的source insight. 在ubuntu中,安装windows程序用wine, ...

  7. 在linux下查看内核版本、gcc版本、操作系统多少位等参数

    1. 查看linux版本 cat /etc/issue Ubuntu 11.04 \n \l 2. 查看内核版本 1)cat /proc/version Linux version 2.6.38-13 ...

  8. 常用HTML meta 标签属性(网站兼容与优化需要),meta标签

    常用HTML meta 标签属性(网站兼容与优化需要),meta标签 标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索 ...

  9. Berkeley DB

    最近用BDB写点东西,写了挺多个测试工程.列下表,也理清楚最近的思路 1.测试BDB程序,包括打开增加记录,查询记录,获取所有记录.将数据转存mysql 程序的不足,增加记录仅仅只有key和value ...

  10. [大牛翻译系列]Hadoop(9)MapReduce 性能调优:理解性能瓶颈,诊断map性能瓶颈

    6.2 诊断性能瓶颈 有的时候作业的执行时间会长得惊人.想靠猜也是很难猜对问题在哪.这一章中将介绍如何界定问题,找到根源.涉及的工具中有的是Hadoop自带的,有的是本书提供的. 系统监控和Hadoo ...