CF182A.Battlefield
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya lagged behind at the University and got to the battlefield. Just joking! He's simply playing some computer game. The field is a flat platform with n trenches dug on it. The trenches are segments on a plane parallel to the coordinate axes. No two trenches intersect.
There is a huge enemy laser far away from Vasya. The laser charges for a seconds, and then shoots continuously for b seconds. Then, it charges for a seconds again. Then it shoots continuously for b seconds again and so on. Vasya knows numbers a and b. He also knows that while the laser is shooting, Vasya must be in the trench, but while the laser is charging, Vasya can safely move around the field. The main thing is to have time to hide in the trench before the shot. If Vasya reaches the trench exactly at the moment when the laser starts shooting, we believe that Vasya managed to hide. Coincidentally, the length of any trench in meters numerically does not exceed b.
Initially, Vasya is at point A. He needs to get to point B. Vasya moves at speed 1 meter per second in either direction. You can get in or out of the trench at any its point. Getting in or out of the trench takes no time. It is also possible to move in the trench, without leaving it.
What is the minimum time Vasya needs to get from point A to point B, if at the initial time the laser has just started charging? If Vasya cannot get from point A to point B, print -1. If Vasya reaches point B at the moment when the laser begins to shoot, it is believed that Vasya managed to reach point B.
瓦西娅在大学里落下了功课,结果上了战场。开个玩笑!他只是在玩一款电脑游戏而已。战场是一块平坦的平台,上面挖有 n 条战壕。这些战壕是平行于坐标轴的线段。任意两条战壕互不相交。
远处有一台巨大的敌方激光武器,离瓦西娅很远。该激光器先充能 a 秒,然后持续发射 b 秒;接着再次充能 a 秒,再持续发射 b 秒,如此循环往复。瓦西娅已知参数 a 和 b。他还知道:激光发射期间,瓦西娅必须身处某条战壕内;而激光充能期间,瓦西娅可在战场上自由移动。关键在于他必须在激光开始发射前及时躲入战壕。若瓦西娅恰好在激光开始发射的那一刻抵达战壕,则认为他成功躲入。巧合的是,每条战壕的长度(单位:米)在数值上均不超过 b。
初始时刻,瓦西娅位于点 A,他需要到达点 B。瓦西娅在任意方向上的移动速度均为 1 米/秒。他可以在战壕的任意一点进入或离开战壕,且进出战壕不消耗时间。此外,他也可以在战壕内部沿其长度方向移动(不离开战壕)。
若初始时刻激光恰好开始充能,问瓦西娅从点 A 到达点 B 所需的最少时间是多少?若瓦西娅无法从点 A 到达点 B,输出 −1。若瓦西娅恰好在激光开始发射的时刻抵达点 B,则认为他成功到达点 B。
输入格式
The first line contains two space-separated integers: a and b (1 ≤ a, b ≤ 1000), — the duration of charging and the duration of shooting, in seconds.
The second line contains four space-separated integers: A__x, A__y, B__x, B__y ( - 104 ≤ A__x, A__y, B__x, B__y ≤ 104) — the coordinates of points А and B. It is guaranteed that points A and B do not belong to any trench.
The third line contains a single integer: n (1 ≤ n ≤ 1000), — the number of trenches.
Each of the following n lines contains four space-separated integers: _x_1, _y_1, _x_2, _y_2 ( - 104 ≤ x__i, y__i ≤ 104) — the coordinates of ends of the corresponding trench.
All coordinates are given in meters. It is guaranteed that for any trench either _x_1 = _x_2, or _y_1 = _y_2. No two trenches intersect. The length of any trench in meters doesn't exceed b numerically.
第一行包含两个以空格分隔的整数:a 和 b(1 ≤ a, b ≤ 1000),分别表示充电时间和射击时间(单位:秒)。
第二行包含四个以空格分隔的整数:Ax、Ay、Bx、By(−104 ≤ Ax, Ay, Bx, By ≤ 104),表示点 A 和点 B 的坐标。保证点 A 和点 B 均不在任何战壕上。
第三行包含一个整数:n(1 ≤ n ≤ 1000),表示战壕的数量。
接下来的 n 行中,每行包含四个以空格分隔的整数:x1、y1、x2、y2(−104 ≤ xi, yi ≤ 104),表示对应战壕两个端点的坐标。
所有坐标均以米为单位。保证对任意一条战壕,均有 x1=x2 或 y1=y2。任意两条战壕互不相交。任意一条战壕的长度(以米为单位)在数值上不超过 b。
输出格式
If Vasya can get from point A to point B, print the minimum time he will need for it. Otherwise, print number -1.
The answer will be considered correct if the absolute or relative error does not exceed 10 - 4
如果瓦西娅能从点 A 到达点 B,请输出他所需的最短时间;否则,输出数字 −1。
若答案的绝对误差或相对误差不超过 10−4,则视为正确。
输入输出样例
输入#1
2 4 0 5 6 5 3 0 0 0 4 1 1 4 1 6 0 6 4
输出#1
19.0000000000
输入#2
5 10 0 0 10 10 1 5 0 5 9
输出#2
-1
输入解题思路,AI测评打分。不知道怎么写?