Skip to content
balauru edited this page Jun 18, 2012 · 1 revision

There are N points on X-Y plane with integer coordinates (xi, yi). You are given a set of polygons with all of its edges parallel to the axes (in other words, all angles of the polygons are 90 degree angles and all lines are in the cardinal directions. There are no diagonals). For each polygon your program should find the number of points lying inside it (A point located on the border of polygon is also considered to be inside the polygon).

Input:

First line two integers N and Q. Next line contains N space separated integer coordinates (xi,yi). Q queries follow. Each query consists of a single integer Mi in the first line, followed by Mi space separated integer coordinates (x[i][j],y[i][j]) specifying the boundary of the query polygon in clock-wise order.

Polygon is an alternating sequence of vertical line segments and horizontal line segments. Polygon has Mi edges, where (x[i][j],y[i][j]) is connected to (x[i][(j+1)%Mi], y[i][(j+1)%Mi]. For each 0 <= j < Mi, either x[i][(j+1)%Mi] == x[i][j] or y[i][(j+1)%Mi] == y[i][j] but not both. It is also guaranteed that the polygon is not self-intersecting.

Output:

For each query output the number of points inside the query polygon in a separate line.

Sample Input #1:

16 2

0 0

0 1

0 2

0 3

1 0

1 1

1 2

1 3

2 0

2 1

2 2

2 3

3 0

3 1

3 2

3 3

8

0 0

0 1

1 1

1 2

0 2

0 3

3 3

3 0

4

0 0

0 1

1 1

1 0

Sample Output #1:

16

4

Clone this wiki locally