Voronoi diagrams P67490


Statement
 

pdf   zip

Given nn two-dimensional points p1,,pnp_1, \dots, p_n, the plane can be decomposed into nn regions, each one with the places that are closer to some of the points pip_i. This is called the Voronoi diagram of the given set of points. For instance, the points (30,25)(-30,25), (20,5)(-20,-5), (20,15)(-20,15), (10,15)(-10,15), (10,25)(-10,25) and (20,15)(20,15) define the following regions (Cartesian coordinates in blue, points in green, and edges of the regions in black):

(100,80)

(70,00)(70,75) (70,75)(68.5,71) (70,75)(71.5,71) (00,25)(100,25) (100,25)(96,23.5) (100,25)(96,26.5)

(00,20)(15,25) (80,60)(85,75) (50,65)(50,75) (80,10)(85,00)

(30,30)(55,30) (55,30)(55,45) (30,30)(50,50) (15,25)(30,30) (75,20)(75,45) (50,50)(50,65) (55,45)(75,45) (50,50)(55,45) (55,30)(75,20) (75,45)(80,60) (75,20)(80,10)

(40,50)0.5 (50,40)0.5 (50,20)0.5 (60,40)0.5 (60,50)0.5 (90,40)0.5

(30,40)0.5 (90,25)0.5

(30,40)(90,25)

Note that each region is convex. The edges correspond to places equidistant to the two nearest points. The vertices are the places equidistant to three (or more) points.

Given two arbitrary points aa and bb in the plane, the segment that connects them crosses several edges of the Voronoi diagram. How many? For instance, the segment that connects (40,15)(-40,15) and (20,0)(20,0)—in red in the picture—crosses 3 edges.

Input

Input consists of several cases. Each case begins with nn, followed by the coordinates of pip_i for every ii, followed by the coordinates of aa and bb. The coordinates are real numbers with at most two digits after the decimal point. The n+2n + 2 given points and the vertices of the diagram are different and not closer than 0.010.01 units. The segment does not overlap any edge and is not closer than 0.010.01 units to any vertex. Assume 1n1001 \le n \le 100.

Output

For every case, print the number of edges crossed by the segment that connects aa and bb.

Public test cases
  • Input

    6
    -30 25 -20 -5 -20 15 -10 15 -10 25 20 15
    -40 15 20 0
    1
    0 0
    4.21 0 0 2.35
    2
    1 0 0 0
    1 1 0 1
    2
    1 0 0 0
    1 1 2 1
    

    Output

    3
    0
    1
    0
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++