QOJ.ac

QOJ

حد الوقت: 5 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#1649. 簡單凸包

الإحصائيات

Gary 一直試圖為他的幾何作業生成簡單的正交多邊形,但他的演算法似乎出了一些問題。經過幾個小時的除錯後,他終於發現了問題所在:顯然,他生成的「多邊形」可能包含自交(self-intersections),這完全不是他的本意!

更具體地說,Gary 生成的「多邊形」由一系列點 $p_i = (x_i, y_i)$ 表示,形成一條封閉的多邊形鏈。該多邊形鏈可能包含自交。鏈中每兩個連續點 $(x_i, y_i)$ 和 $(x_j, y_j)$ 所形成的線段皆為垂直或水平。

範例測試案例中的多邊形鏈如下圖所示(未按比例繪製):

你決定幫助 Gary 解決這個問題,方法是計算一個包含該鏈的簡單(不自交)正交多邊形(由垂直和水平線段組成),並使其面積盡可能小。這樣的多邊形面積是多少?

形式上,你需要計算所有包含所有線段 $[p_i, p_j]$(對於每兩個相鄰點 $p_i$ 和 $p_j$)的簡單正交多邊形面積的下確界(infimum)。

輸入格式

輸入的第一行包含一個正整數 $n$ ($4 \le n \le 100\,000$)。接下來的 $n$ 行依序包含點 $(x_i, y_i)$ ($1 \le x_i, y_i \le 10^6$)。沒有兩個連續的點重合,且不存在兩個連續的垂直線段或兩個連續的水平線段。

輸出格式

輸出一個非負整數,即包圍該封閉多邊形鏈的所有簡單多邊形面積的下確界。可以證明答案總是一個整數。

範例

輸入格式 1

6
1 1
6 1
6 11
11 11
11 6
1 6

輸出格式 1

50

輸入格式 2

8
2 4
2 1
4 1
4 3
1 3
1 2
3 2
3 4

輸出格式 2

6

輸入格式 3

10
1 1
1 5
4 5
4 3
2 3
2 4
1 4
1 2
4 2
4 1

輸出格式 3

8

說明

在範例 1 和 3 中,不存在面積恰好等於 50 和 8 的簡單多邊形;然而,存在面積任意接近這些值的簡單多邊形。

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.