QOJ.ac

QOJ

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

#17329. 幼兒園重遊

الإحصائيات

在幼稚園裡,最耗時的活動之一就是用安全剪刀從紙上剪下各種形狀。讓我們看看這個任務的簡化模型:你從一張無限大的紙開始,上面畫有 $N$ 個不相交的軸對齊矩形,而剪裁是無限長的直線。剪裁不得「切到」任何矩形:它不能穿過任何矩形內部的點。(允許沿著矩形邊緣或穿過矩形頂點的剪裁。)當你剪開一張紙時,紙張會分成兩塊不同的紙片,你可以繼續獨立地剪裁它們(在其中一塊紙片上的後續剪裁不會影響其他紙片)。

你的目標是進行一系列的剪裁,使得每個矩形最終都位於其獨立的紙片上(因為在那之後,要精確地剪下每個矩形就很容易了)。

請確定將矩形以這種方式分離所需的最小剪裁次數(不一定是軸對齊的)。如果任務是不可能的,請輸出 impossible

輸入格式

第一行包含一個整數 $N$ ($1 \le N \le 100$),代表矩形的數量。

接下來的 $N$ 行描述每個矩形。每行包含四個以空格分隔的整數 $x_1, y_1, x_2, y_2$ ($|x_1|, |y_1|, |x_2|, |y_2| \le 10^9, x_1 < x_2, y_1 < y_2$),其中 $(x_1, y_1)$ 是矩形的左下角,$(x_2, y_2)$ 是矩形的右上角。

保證矩形是不相交的:沒有兩個矩形在任何點(包括邊緣或頂點)上有交集。

輸出格式

輸出分離所有矩形所需的最小剪裁次數。(一旦分離,不需要包含為了修剪矩形周圍邊緣的空白紙張而進行的額外剪裁。)如果任務是不可能的,請輸出 impossible

說明

範例輸入 1 中,分離矩形的一種可能剪裁序列的前兩次剪裁如下圖所示。第一次剪裁以紅色繪製,第二次以藍色繪製。請注意,藍色剪裁在紅色剪裁之前是無效的,因為它會切到右側的矩形。

範例

輸入 1

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

輸出 1

5

輸入 2

4
0 -1 1 2
2 -1 5 0
-10 3 3 4
4 1 5 13

輸出 2

impossible

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.