1665. Points Within

单点时限: 2.0 sec

内存限制: 256 MB

Several drawing applications allow us to draw polygons and almost all of them allow us to fill them with some color. The task of filling a polygon reduces to knowing which points are inside it, so programmers have to colour only those points.

You’re expected to write a program which tells us if a given point lies inside a given polygon described by the coordinates of its vertices. You can assume that if a point is in the border of the polygon, then it is in fact inside the polygon.

输入格式

The input file may contain several instances of the problem. Each instance consists of: (i) one line containing integers N, 0 < N < 100 and M, respectively the number of vertices of the polygon and the number of points to be tested. (ii) N lines, each containing a pair of integers describing the coordinates of the polygon’s vertices; (iii) M lines, each containing a pair of integer coordinates of the points which will be tested for “withinness” in the polygon.

You may assume that: the vertices are all distinct; consecutive vertices in the input are adjacent in the polygon; the last vertex is adjacent to the first one; and the resulting polygon is simple, that is, every vertex is incident with exactly two edges and two edges only intersect at their common endpoint. The last instance is followed by a line with a 0 (zero).

输出格式

For the ith instance in the input, you have to write one line in the output with the phrase “Problem i:”, followed by several lines, one for each point tested, in the order they appear in the input. Each of these lines should read “Within” or “Outside”, depending on the outcome of the test. The output of two consecutive instances should be separated by a blank line.

样例

Input
3 1
0 0
0 5
5 0
10 2
3 2
4 4
3 1
1 2
1 3
2 2
0
Output
Problem 1:
Outside
Problem 2:
Outside
Within

8 人解决,9 人已尝试。

14 份提交通过,共有 34 份提交。

5.8 EMB 奖励。

创建: 16 年,9 月前.

修改: 6 年,10 月前.

最后提交: 11 月,3 周前.

来源: South America 2001

题目标签