#P12628. [NAC 2025] Polygon Partition

[NAC 2025] Polygon Partition

题目描述

A simple polygon is a polygon that is not self-intersecting and does not contain any holes. You are given the NN vertices of a simple polygon, v1v_1, v2v_2, \ldots, vNv_N, where vi=(xi,yi)v_i = (x_i, y_i), and xix_i and yiy_i are the xx-coordinate and yy-coordinate of the ithi^{\textrm{th}} vertex, respectively. The vertices are distinct and given in counterclockwise order (so there is an edge between each pair of consecutive vertices; there is also an edge from vNv_N back to v1v_1).

The polygon's boundary does not pass through any lattice points (a lattice point is a point where both coordinates are integers). In addition, none of the xix_i or yiy_i values are exactly an integer.

A semi-integer point is a point where exactly one of its coordinates is an integer. Let P={p1,p2,,pk}\mathcal{P} = \left\{p_1, p_2, \ldots, p_k\right\} be all of the semi-integer points that lie on the boundary of the polygon. For each semi-integer point pip_i in P\mathcal{P}, let nin_i be the floor of the non-integer coordinate of pip_i. For a subset S\mathcal{S} of P\mathcal{P}, let σ(S)\sigma(\mathcal{S}) be the sum of the nin_i of the points in S\mathcal{S} (with σ()=0\sigma(\emptyset) = 0). Does there exist a partition of P\mathcal{P} into two subsets S1\mathcal{S}_1 and S2\mathcal{S}_2 so that the σ(S1)=σ(S2)\sigma(\mathcal{S}_1) = \sigma(\mathcal{S}_2)?

(Two sets S1\mathcal{S}_1 and S2\mathcal{S}_2 are a partition of P\mathcal{P} if P=S1S2\mathcal{P} = \mathcal{S}_1 \cup \mathcal{S}_2 and S1S2=\mathcal{S}_1 \cap \mathcal{S}_2 = \emptyset. There are no other restrictions on S1\mathcal{S}_1 and S2\mathcal{S}_2 so long as these two conditions hold and σ(S1)=σ(S2)\sigma(\mathcal{S}_1) = \sigma(\mathcal{S}_2). In particular, empty sets are allowed, and the semi-integer points in each set do not have to be contiguous around the polygon boundary.)

输入格式

The first line of input contains one integer NN (3N5003 \leq N \leq 500), the number of vertices of the polygon.

Each of the next NN lines contains two space-separated real numbers xix_i and yiy_i (500<xi,yi<500-500 < x_i, y_i < 500): the coordinates of the polygon vertices, in counterclockwise order. Each coordinate will have exactly 66 digits after the decimal point and will not be exactly an integer.

It is guaranteed that the polygon does not self-intersect, that the vertices are distinct, and that the polygon boundary does not pass through any lattice points.

输出格式

If there is no solution, print 1-1 and no further output.

Otherwise, print a single integer MM on its own line: the number of semi-integer points in one of the two subsets in a valid partition of P\mathcal{P}. On the next MM lines of output, print the values nin_i for the points in that subset, one per line.

If there are multiple valid partitions, you may choose any of them. You may print either of its two subsets, and you may list the subset's nin_i values in any order.

4
-0.950000 -0.850000
-0.100000 0.999999
0.111000 0.555000
-0.200000 1.600000
3
0
-1
-1
3
0.500000 0.700000
0.100000 0.200000
0.800000 0.900000
0
4
-360.000001 -24.000001
-359.999999 -24.000001
-359.999999 -23.999999
-360.000001 -23.999999
2
-25
-360

提示

Sample Input 1 is shown in the image below:

The points of the vertices are labeled A,B,C,DA,B,C,D. The semi-integer points are marked in orange and labeled pip_i going counterclockwise around the perimeter starting from AA. The values nin_i of the semi-integer points are, in the same order, 1,0,0,1,1,1-1, 0, 0, -1, -1, -1. Any subset of those values that sum to 2-2 would be accepted as correct. Sample Output 1 shows one possible correct answer.

The boundary of the polygon in Sample Input 2 does not intersect any semi-integer points, so P\mathcal{P} is empty, and it can be partitioned into two empty sets each with nin_i sum of zero.