CF142E.Help Greg the Dwarf 2

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And in the morning he should be in his crypt before the first sun ray strikes. That's why he wants to find the shortest route from the excavation point to his crypt. Greg has recollected how the Codeforces participants successfully solved the problem of transporting his coffin to a crypt. So, in some miraculous way Greg appeared in your bedroom and asks you to help him in a highly persuasive manner. As usual, you didn't feel like turning him down.

After some thought, you formalized the task as follows: as the Neverland mountain has a regular shape and ends with a rather sharp peak, it can be represented as a cone whose base radius equals rr and whose height equals hh . The graveyard where Greg is busy excavating and his crypt can be represented by two points on the cone's surface. All you've got to do is find the distance between points on the cone's surface.

The task is complicated by the fact that the mountain's base on the ground level and even everything below the mountain has been dug through by gnome (one may wonder whether they've been looking for the same stuff as Greg...). So, one can consider the shortest way to pass not only along the side surface, but also along the cone's base (and in a specific case both points can lie on the cone's base — see the first sample test)

Greg will be satisfied with the problem solution represented as the length of the shortest path between two points — he can find his way pretty well on his own. He gave you two hours to solve the problem and the time is ticking!

输入格式

The first input line contains space-separated integers rr and hh ( 1<=r,h<=10001<=r,h<=1000 ) — the base radius and the cone height correspondingly. The second and third lines contain coordinates of two points on the cone surface, groups of three space-separated real numbers. The coordinates of the points are given in the systems of coordinates where the origin of coordinates is located in the centre of the cone's base and its rotation axis matches the OZOZ axis. In this coordinate system the vertex of the cone is located at the point (0,0,h)(0,0,h) , the base of the cone is a circle whose center is at the point (0,0,0)(0,0,0) , lying on the XOYXOY plane, and all points on the cone surface have a non-negative coordinate zz . It is guaranteed that the distances from the points to the cone surface do not exceed 101210^{-12} . All real numbers in the input have no more than 16 digits after decimal point.

输出格式

Print the length of the shortest path between the points given in the input, with absolute or relative error not exceeding 10610^{-6} .

输入输出样例

  • 输入#1

    2 2
    1.0 0.0 0.0
    -1.0 0.0 0.0
    

    输出#1

    2.000000000
  • 输入#2

    2 2
    1.0 0.0 0.0
    1.0 0.0 1.0
    

    输出#2

    2.414213562
  • 输入#3

    2 2
    1.0 0.0 1.0
    -1.0 0.0 1.0
    

    输出#3

    2.534324263
  • 输入#4

    2 2
    1.0 0.0 0.0
    0.0 1.0 1.0
    

    输出#4

    3.254470198
首页