CF1552C.Maximize the Intersections
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
On a circle lie 2n distinct points, with the following property: however you choose 3 chords that connect 3 disjoint pairs of points, no point strictly inside the circle belongs to all 3 chords. The points are numbered 1,2,…,2n in clockwise order.
Initially, k chords connect k pairs of points, in such a way that all the 2k endpoints of these chords are distinct.
You want to draw n−k additional chords that connect the remaining 2(n−k) points (each point must be an endpoint of exactly one chord).
In the end, let x be the total number of intersections among all n chords. Compute the maximum value that x can attain if you choose the n−k chords optimally.
Note that the exact position of the 2n points is not relevant, as long as the property stated in the first paragraph holds.
一个圆上分布着 2n 个互异的点,满足如下性质:无论你如何选取三条弦(每条弦连接一对互不相交的点),都不存在严格位于圆内部、同时属于这三条弦的公共点。这些点按顺时针顺序编号为 1,2,…,2n。
初始时,已有 k 条弦连接了 k 对点,且这 k 条弦的全部 2k 个端点互不相同。
你需要再画出 n−k 条弦,将剩余的 2(n−k) 个点两两配对(每个剩余点恰好作为一条弦的一个端点)。
最终,设 x 为全部 n 条弦之间的交点总数(交点必须严格位于圆内部)。若你可以最优地选择这 n−k 条新弦,求 x 的最大可能值。
注意:2n 个点在圆上的具体位置并不重要,只要满足第一段所述的性质即可。
输入格式
The first line contains a single integer t (1≤t≤100) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and k (1≤n≤100, 0≤k≤n) — half the number of points and the number of chords initially drawn.
Then k lines follow. The i-th of them contains two integers xi and yi (1≤xi,yi≤2n, xi=yi) — the endpoints of the i-th chord. It is guaranteed that the 2k numbers x1,y1,x2,y2,…,xk,yk are all distinct.
第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤100,0≤k≤n),分别表示点的总数的一半以及初始已画出的弦的数量。
接下来是 k 行。其中第 i 行包含两个整数 xi 和 yi(1≤xi,yi≤2n,xi=yi),表示第 i 条弦的两个端点。保证这 2k 个数 x1,y1,x2,y2,…,xk,yk 互不相同。
输出格式
For each test case, output the maximum number of intersections that can be obtained by drawing n−k additional chords.
对于每个测试用例,输出通过再画 n−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 2 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 4.
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−3 and 2−4, as shown below:

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

可见,第三种画法产生的交点数最多,为 4 个。
在第二个测试用例中,无需再画任何弦。显然,仅存在一条弦时,交点数为 0。
在第三个测试用例中,我们最多只能得到一个交点,方法是画出弦 1-3 和 2-4,如下图所示:

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