CF1552C.Maximize the Intersections

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

On a circle lie 2n2n distinct points, with the following property: however you choose 33 chords that connect 33 disjoint pairs of points, no point strictly inside the circle belongs to all 33 chords. The points are numbered 1, 2, …, 2n1, \, 2, \, \dots, \, 2n in clockwise order.

Initially, kk chords connect kk pairs of points, in such a way that all the 2k2k endpoints of these chords are distinct.

You want to draw n−kn - k additional chords that connect the remaining 2(n−k)2(n - k) points (each point must be an endpoint of exactly one chord).

In the end, let xx be the total number of intersections among all nn chords. Compute the maximum value that xx can attain if you choose the n−kn - k chords optimally.

Note that the exact position of the 2n2n points is not relevant, as long as the property stated in the first paragraph holds.

一个圆上分布着 2n2n 个互异的点,满足如下性质:无论你如何选取三条弦(每条弦连接一对互不相交的点),都不存在严格位于圆内部、同时属于这三条弦的公共点。这些点按顺时针顺序编号为 1, 2, …, 2n1,\, 2,\, \dots,\, 2n。

初始时,已有 kk 条弦连接了 kk 对点,且这 kk 条弦的全部 2k2k 个端点互不相同。

你需要再画出 n−kn - k 条弦,将剩余的 2(n−k)2(n - k) 个点两两配对(每个剩余点恰好作为一条弦的一个端点)。

最终,设 xx 为全部 nn 条弦之间的交点总数(交点必须严格位于圆内部)。若你可以最优地选择这 n−kn - k 条新弦,求 xx 的最大可能值。

注意:2n2n 个点在圆上的具体位置并不重要,只要满足第一段所述的性质即可。

输入格式

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. Then tt test cases follow.

The first line of each test case contains two integers nn and kk (1≤n≤1001 \le n \le 100, 0≤k≤n0 \le k \le n) — half the number of points and the number of chords initially drawn.

Then kk lines follow. The ii-th of them contains two integers xix_i and yiy_i (1≤xi, yi≤2n1 \le x_i, \, y_i \le 2n, xi≠yix_i \ne y_i) — the endpoints of the ii-th chord. It is guaranteed that the 2k2k numbers x1, y1, x2, y2, …, xk, ykx_1, \, y_1, \, x_2, \, y_2, \, \dots, \, x_k, \, y_k are all distinct.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤1001 \le n \le 100,0≤k≤n0 \le k \le n),分别表示点的总数的一半以及初始已画出的弦的数量。

接下来是 kk 行。其中第 ii 行包含两个整数 xix_i 和 yiy_i(1≤xi, yi≤2n1 \le x_i, \, y_i \le 2n,xi≠yix_i \ne y_i),表示第 ii 条弦的两个端点。保证这 2k2k 个数 x1, y1, x2, y2, …, xk, ykx_1, \, y_1, \, x_2, \, y_2, \, \dots, \, x_k, \, y_k 互不相同。

输出格式

For each test case, output the maximum number of intersections that can be obtained by drawing n−kn - k additional chords.

对于每个测试用例,输出通过再画 n−kn - k 条弦所能得到的最大交点数。

输入输出样例

  • 输入#1

    4
    4 2
    8 2
    1 5
    1 1
    2 1
    2 0
    10 6
    14 6
    2 20
    9 10
    13 18
    15 12
    11 7

    输出#1

    4
    0
    1
    14

说明/提示

In the first test case, there are three ways to draw the 22 additional chords, shown below (black chords are the ones initially drawn, while red chords are the new ones):

We see that the third way gives the maximum number of intersections, namely 44.

In the second test case, there are no more chords to draw. Of course, with only one chord present there are no intersections.

In the third test case, we can make at most one intersection by drawing chords 1−31-3 and 2−42-4, as shown below:

在第一个测试用例中,有三种方式可以画出额外的 22 条弦,如下图所示(黑色弦为初始已画出的弦,红色弦为新增的弦):

可见,第三种画法产生的交点数最多,为 44 个。

在第二个测试用例中,无需再画任何弦。显然,仅存在一条弦时,交点数为 00。

在第三个测试用例中,我们最多只能得到一个交点,方法是画出弦 1-31\text{-}3 和 2-42\text{-}4,如下图所示:

输入解题思路,AI测评打分。不知道怎么写?

首页