#P7058. [NWRRC 2015] Kingdom Trip

[NWRRC 2015] Kingdom Trip

题目描述

Once upon a time, there was a kingdom ruled by a wise king. After forty three years of his reign, by means of successful military actions and skillful diplomacy, the kingdom became an infinite flat two-dimensional surface. This form of the kingdom greatly simplified travelling, as there were no borders.

A big holiday was planned in the kingdom. There were nn locations for people to gather. As the king wanted to have a closer look at his people, he ordered to make a trip through these locations. He wanted to give a speech in each of these locations. Initially his trip was designed as a polygonal chain pp : p1p2p_{1} \to p_{2} \to . . . pn. \to p_{n}.

Not only the king was wise, but he was old, too. Therefore, his assistants came up with an idea to skip some locations, to make the king to give as few speeches as possible. The new plan of the trip has to be a polygonal chain consisting of some subsequence of pp : starting at p1p_{1} and ending at pn,p_{n}, formally, pi1pi2pim,p_{i_{1}} \to p_{i_{2}} \to · · · \to p_{i_{m}}, where 1=i1<i2<<im=n1 = i_{1} < i_{2} < · · · < i_{m} = n . Assistants know that the king wouldn't allow to skip location jj , if the distance from pjp_{j} to segment pikpik+1p_{i_{k}} \to p_{i_{k+1}} exceeds dd , for such kk , that ik<j<ik+1.i_{k} < j < i_{k+1}.

Original route

New route

Help the assistants to find the new route that contains the minimum possible number of locations.

输入格式

The first line of the input file contains two integers nn and dd -- the number of locations in the initial plan of the trip and the maximum allowed distance to skipped locations (2n2000(2 \le n \le 2000 ; 1d106).1 \le d \le 10^{6}).

The following nn lines describe the trip. The i-th of these lines contains two integers xix_{i} and yiy_{i} -- coordinates of point pi.p_{i}. The absolute value of coordinates does not exceed 106.10^{6}. No two points coincide.

输出格式

Output the minimum number of locations the king will visit. It is guaranteed that the answer is the same for d±104.d ± 10^{−4}.

5 2
2 6
8 2
14 2
12 9
13 8

3

提示

Time limit: 2 s, Memory limit: 256 MB.