CF182A.Battlefield

普及/提高-

通过率:0%

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 nn 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 aa seconds, and then shoots continuously for bb seconds. Then, it charges for aa seconds again. Then it shoots continuously for bb seconds again and so on. Vasya knows numbers aa and bb . 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 bb .

Initially, Vasya is at point AA . He needs to get to point BB . 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 AA to point BB , if at the initial time the laser has just started charging? If Vasya cannot get from point AA to point BB , print -1. If Vasya reaches point BB at the moment when the laser begins to shoot, it is believed that Vasya managed to reach point BB .

输入格式

The first line contains two space-separated integers: aa and bb (1<=a,b<=1000)(1<=a,b<=1000) , — the duration of charging and the duration of shooting, in seconds.

The second line contains four space-separated integers: AxA_{x} , AyA_{y} , BxB_{x} , ByB_{y} (104<=Ax,Ay,Bx,By<=104)(-10^{4}<=A_{x},A_{y},B_{x},B_{y}<=10^{4}) — the coordinates of points АА and BB . It is guaranteed that points AA and BB do not belong to any trench.

The third line contains a single integer: nn (1<=n<=1000)(1<=n<=1000) , — the number of trenches.

Each of the following nn lines contains four space-separated integers: x1x_{1} , y1y_{1} , x2x_{2} , y2y_{2} (104<=xi,yi<=104)(-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 x1=x2x_{1}=x_{2} , or y1=y2y_{1}=y_{2} . No two trenches intersect. The length of any trench in meters doesn't exceed bb numerically.

输出格式

If Vasya can get from point AA to point BB , 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 10410^{-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
    
首页