Codeforces Round 117 (Div. 2)
A
Battlefield
Codeforces
2200
原题
←B →
翻译中…

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*$.

翻译中…

Input

翻译中…

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*}$ $( - 10^{4} ≤ *A*_{*x*}, *A*_{*y*}, *B*_{*x*}, *B*_{*y*} ≤ 10^{4})$ — 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}$ $( - 10^{4} ≤ *x*_{*i*}, *y*_{*i*} ≤ 10^{4})$ — 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.

翻译中…

Output

翻译中…

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}$

翻译中…

样例

Input #1
2 4
0 5 6 5
3
0 0 0 4
1 1 4 1
6 0 6 4
Output #1
19.0000000000
InputCopy OutputCopy
Input #2
5 10
0 0 10 10
1
5 0 5 9
Output #2
-1
InputCopy OutputCopy
题目信息
题号
182A
时间限制
2 s
内存限制
256 MB
标签
计算几何
图论
模拟
最短路

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。