P27971 [洛谷] [ROIR 2023 Day 1] Colored Points
提高+
题目描述

Problem Background

Translated from ROIR 2023 D1T4.

There are $n$ points on a plane, denoted as $P_1, P_2, P_3, \dots, P_n$. The coordinates of the $i$-th point are $(x_i, y_i)$.

Select two points $P_i$ and $P_j$ ($i \ne j$). Let $P_i$ be the starting point and $P_j$ be the ending point. Centered at the ending point $P_j$, sort the points (excluding $P_j$) in a counterclockwise order starting from the direction of the vector $\overrightarrow{P_iP_j}$ (if angles are the same, sort by ascending distance to point $P_j$). Suppose the $t$-th point in the sorted order is $P_k$, then repeat the operation with $P_j$ as the starting point and $P_k$ as the new ending point, sorting and calculating the new ending point's index in the same manner. This process continues in a loop.

In the figure below, initially $n=6, t=4, i=1, j=2$. Sorting the points except $P_2$ in order gives $P_3, P_5, P_1, P_6, P_4$, so the next ending point should be $P_6$, with $P_2$ as the starting point.

Now $n=6, t=4, i=2, j=6$. Continuing the sorting as per the rules, as shown in the left diagram below, the result is $P_4, P_3, P_2, P_1, P_5$. Thus, the next ending point is $P_1$, with $P_6$ as the starting point.

Now $n=6, t=4, i=6, j=1$. Continuing the sorting as per the rules, as shown in the right diagram above, the result is $P_5, P_6, P_4, P_2, P_3$. Thus, the next ending point is $P_2$, with $P_1$ as the starting point. At this point, we return to the initial situation, entering a loop.

Problem Description

We will color each of the $n$ points with one of three colors. The color of the $i$-th point is determined as follows:

  • If there exists a point $j$ such that choosing point $i$ as the starting point and point $j$ as the ending point, point $i$ will become the starting point infinitely many times in the process described above, then color point $i$ green.
  • If point $i$ is not colored green and there exists a point $j$ such that choosing point $i$ as the starting point and point $j$ as the ending point, point $i$ will become the starting point at least once more in the process, then color point $i$ blue.
  • If point $i$ is neither green nor blue, then color point $i$ red.

Determine the color each point should be painted.

Input Format

The first line contains two integers $n$ and $t$.

The next $n$ lines each contain two integers $x_i$ and $y_i$. It is guaranteed that no two points coincide.

Output Format

Output a single line containing $n$ characters, where the $i$-th character represents the color of the $i$-th point.

Green points are represented by the letter G, blue points by the letter B, and red points by the letter R.

Sample Input and Output

Sample Input #1

6 4
-1 -1
1 -2
4 -2
2 -4
2 3
-4 -5

Sample Output #1

GGBBRG

Sample Input #2

2 1
1 1
2 2

Sample Output #2

GG

Notes

Sample $1$ Explanation:

From the example given earlier, it is known that $P_1, P_2, P_6$ form a loop and will be visited infinitely many times, so these points should be colored green.

When the starting point is $P_3$, choosing $P_1$ as the ending point, after sorting, $P_3$ is exactly the fourth point, thus bringing $P_3$ back to the starting point, as shown in the figure below. Therefore, it should be colored blue.

When the starting point is $P_4$, choosing $P_5$ as the ending point, after sorting, $P_4$ is exactly the fourth point. Therefore, $P_4$ can be colored blue. When $P_5$ is the starting point, it is easy to see that it cannot be colored green or blue, so it should be colored red.

This problem uses bundled test cases.

Subtask Points Special Conditions
1 10 $n \le 10$, all points collinear
2 15 All points collinear
3 10 $n \le 10$, no blue points
4 10 $n \le 10$
5 15 $n \le 100$, no blue points
6 15 $n \le 100$
7 5 $n \ge 3$, all points form a strictly convex $n$-gon, input in counterclockwise order
8 20 None

For all data, $2 \le n \le 1000, 1 \le t \le n-1, -10^9 \le x_i, y_i \le 10^9$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 4 -1 -1 1 -2 4 -2 2 -4 2 3 -4 -5
样例输出
GGBBRG