QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#19989. 隐藏的字形

Statistics

Glyph Yuji 喜爱旅行,并在不同国家发现各种字形。经过几年的旅行,Glyph 发现他在 Lollipop 和 Boomerang 两个国家找到的字形存在相似之处。这两个地方的手写系统非常相似:所有用于手写的字形都是矩形状的。

一个矩形状的字形可以建模为二维欧几里得平面上的简单多边形,多边形的每条边都与坐标轴平行或垂直。

通过进一步研究 Lollipop 和 Boomerang 使用的两种语言,Glyph 得出了一些观察结果:(1) Lollipop 的字形通常比 Boomerang 的字形大。(2) 每种语言恰好有 $n$ 个不同的字形,且两者之间存在一一对应关系。

然而,Glyph 不知道 Lollipop 语言中的哪个字形对应 Boomerang 语言中的哪个字形。为了探索这种对应关系,Glyph 首先将每个字形描述为一个简单多边形。

problem_19989_827b1255428b6d226d13c698a02abd99.png

图 1:Lollipop 国的字形(左)、Boomerang 国对应的字形(中)以及可能的平移区域(右)。(以左下角为 $(0,0)$。)

形式化地,对于一个区域 $B$ 和一个点 $(x,y)$,Glyph 定义 $B+(x,y)$ 为集合 $B+(x,y):=\{(b_x+x,b_y+y)\mid(b_x,b_y)\in B\}$。对于 Lollipop 的每个字形 $L$ 和 Boomerang 的每个字形 $B$,Glyph 定义“平移面积” $\operatorname{tr}(L,B)$ 为区域 $\operatorname{tr}(L,B):=\{(x,y)\mid B+(x,y)\subseteq L\}$ 的面积。参见图 1 的例子。

Glyph Yuji 认为,两种语言之间的真实对应关系一定使所有匹配字形对的平移面积之和最大。注意,在这个定义下,一对字形的平移面积可能为 0。你能帮助 Glyph 求出这个值吗?

输入格式

第一行包含一个整数 $T$,表示测试用例的数量。

每个测试用例以一个整数 $n$ 开始,随后有 $2n$ 行。前 $n$ 行描述代表 Lollipop 语言字形的 $n$ 个矩形状图形,后 $n$ 行描述代表 Boomerang 语言字形的 $n$ 个矩形状图形。

描述矩形状图形的第 $i$ 行包含一个整数 $m_i$,表示顶点数,随后有 $m_i$ 对整数坐标,按照顺时针或逆时针顺序列出。

  • $1\le T\le4$

  • $1\le n\le30$

  • $4\le m_i\le200$

  • 对所有坐标 $(x,y)$,有 $0\le x,y\le1000$。

  • 所有矩形状图形都是合法、非退化的简单多边形。

输出格式

对于每个测试用例,输出一行,其中仅包含一个整数,表示所有匹配字形对的平移面积之和的最大值。可以证明,答案一定是整数。

样例

输入格式 1

2
1
10 0 0 0 10 2 10 2 12 6 12 6 8 2 8 2 4 6 4 6 0
8 0 0 0 3 2 3 2 2 1 2 1 1 2 1 2 0
2
5 0 0 0 2 0 5 5 5 5 0
4 0 0 3 0 3 6 0 6
4 0 0 1 0 1 2 0 2
4 0 0 0 1 2 1 2 0

输出格式 1

6
20

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.