#P9568. [SDCPC2023] Computational Geometry

[SDCPC2023] Computational Geometry

题目描述

Given a convex polygon PP with nn vertices, you need to choose three vertices of PP, denoted as aa, bb and cc in counter-clockwise order. There must be exactly kk edges from bb to cc in counter-clockwise order (that is to say, aa is not an endpoint of these kk edges).

Consider cutting through PP with segment abab and acac. Let QQ be the polygon consisting of abab, acac and the kk edges between bb and cc. It's easy to see that this polygon has (k+2)(k + 2) edges.

Find the maximum possible area of QQ.

Note that abab and acac can overlap with edges of PP.

输入格式

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains two integers nn and kk (3n1053 \le n \le 10^5, 1kn21 \le k \le n-2) indicating the number of vertices of the convex polygon PP and the number of edges from bb to cc in counter-clockwise order.

For the following nn lines, the ii-th line contains two integers xix_i and yiy_i (109xi,yi109-10^9 \le x_i, y_i \le 10^9) indicating the xx and yy coordinate of the ii-th vertex of the convex polygon PP. Vertices are given in counter-clockwise order. It's guaranteed that the area of the convex polygon is positive, and there are no two vertices with the same coordinate. It's possible that three vertices lie on the same line.

It's guaranteed that the sum of nn of all test cases will not exceed 10510^5.

输出格式

For each test case output one line containing one real number indicating the maximum possible area of QQ. Your answer will be considered correct if its relative or absolute error is less than 10910^{-9}.

题目大意

【题目描述】

给定一个有 nn 个顶点的凸多边形 PP,您需要选择 PP 的三个顶点,按逆时针顺序记为 aabbcc。要求在 bb 沿逆时针方向到 cc 之间恰有 kk 条边(也就是说,aa 不是这 kk 条边的端点)。

考虑用线段 ababacacPP 割开。将由线段 ababacac,以及 bbcc 之间的 kk 条边围成的 (k+2)(k + 2) 边形记作 QQ

QQ 可能的最大面积。

注意,ababacac 可以与 PP 的边重合。

【输入格式】

有多组测试数据。第一行输入一个整数 TT 表示测试数据组数。对于每组测试数据:

第一行输入两个整数 nnkk3n1053 \le n \le 10^51kn21 \le k \le n-2),表示凸多边形 PP 的顶点数和 bb 沿逆时针方向到 cc 之间的边数。

对于接下来的 nn 行,第 ii 行输入两个整数 xix_iyiy_i109xi,yi109-10^9 \le x_i, y_i \le 10^9),表示凸多边形 PPii 个顶点的 xx 坐标和 yy 坐标。顶点按逆时针顺序给出。保证凸多边形的面积为正,且没有顶点会重合。可能存在三个顶点位于同一条直线上的情况。

保证所有数据 nn 之和不超过 10510^5

【输出格式】

每组数据输出一行一个实数表示 QQ 的最大可能面积。只要您的答案的相对误差或绝对误差小于10910^{-9} 即视为正确。

【样例解释】

对于第一组样例数据,QQ 就是整个三角形,面积为 0.50.5.

第二和第三组样例数据解释如下。

3
3 1
0 0
1 0
0 1
8 3
1 2
3 1
5 1
7 3
8 6
5 8
3 7
1 5
7 2
3 6
1 1
3 1
7 1
8 1
5 6
4 6

0.500000000000
26.500000000000
20.000000000000

提示

For the first sample test case, QQ is the whole triangle. Its area is 0.50.5.

The second and third sample test case are shown below.