Orienteering

면접 대비

시간 제한5초메모리 제한1024 MB

요약
반지름이 같은 서로 겹치지 않는 N개의 원이 방문 순서대로 주어질 때, 첫 번째 원 안에서 시작해 순서대로 각 원에 들어가 마지막 원에 도착하는 최단 경로의 길이를 구한다.
난이도

보통10점 중 6점

유형
기하, 동적 계획법, 그리디
정답자
아직 제출이 없습니다

문제

Khodislav has taken up orienteering and is participating in a contest. The field is an endless plane without obstacles, and he can move at the same speed in all directions. There are NN checkpoints in the field, where every participant must visit in the ascending order of their numbers. The check-in system is contactless --- each checkpoint has a base station that automatically checks in any participant in a range less than or equal to RR. It is guaranteed that checkpoint coverage areas do not overlap, but they can touch each other.

A participant starts at any point of the first checkpoint coverage and finishes at the moment of checking in at the last checkpoint. Participants are allowed to enter other checkpoint coverage areas on their way to the necessary checkpoint, but in this case, they are not checked in there.

Khodislav is feeling lucky and believes he will be able to cover the distance optimally. Help him calculate the distance he will have to cover.

입력

The first line of the input file contains two integers: NN --- the number of checkpoints (2≤N≤1002 \le N \le 100) and RR --- the check-in radius(1≤R≤1091 \le R \le 10^9).

Next come NN lines describing the checkpoints in the required check-in order. Each line is a pair of integers x_ix\_i, y_iy\_i with the coordinates(−109≤x_i,y_i≤109)-10^9 \le x\_i, y\_i \le 10^9).

출력

Print one real number --- the distance passed if the route is optimal.

The relative or absolute error must not be greater than 0.01. This means that if the optimal answer equals XX, your answer must differ from XX by no more than 1100max⁡(X,1)\frac{1}{100} \max(X, 1).

힌트

Khodislav starts at (0,0)(0, 0), checks in at the second checkpoint at (0,97)(0, 97), turns and checks in at the third checkpoint at (0,53)(0,53). The total distance covered is 97+44=14197 + 44 = 141.

예제1

  1. 예제 1

    입력
    3 3
    0 -3
    0 100
    0 50
    
    예상 출력
    141.0