QOJ.ac

QOJ

Time Limit: 60 s Memory Limit: 64 MB Total points: 20

#23755. 長方形薄片

Statistics

題目描述

平面上放置了若干張長方形的薄片。請撰寫一個程式,求出被這些薄片覆蓋的部分的面積或周長。

不過,當將平面視為座標平面時,設薄片的放置滿足以下條件 $(1)$、$(2)$。

  • $(1)$ 每張長方形薄片的 $4$ 個頂點的 $x, y$ 座標皆為 $0$ 以上 $10000$ 以下的整數,且長方形的各條邊皆平行於 $x$ 軸或 $y$ 軸。
  • $(2)$ 薄片的張數至多為 $10000$ 張以下。

輸入檔案的檔名為 input.txt。input.txt 的第 $1$ 行寫有以空白分隔的長方形個數 $n$ 與表示問題種類的整數 $r$。第 $2$ 行及之後的每一行,寫有每張薄片的左下頂點座標 $(x_1, y_1)$ 與右上頂點座標 $(x_2, y_2)$ 的座標值,依 $x_1, y_1, x_2, y_2$ 的順序以空白分隔。

輸出檔案的檔名為 output.txt。在 output.txt 中,當 $r = 1$ 時在第 $1$ 行輸出面積,當 $r = 2$ 時在第 $1$ 行輸出面積、在第 $2$ 行輸出周長。無論哪種情況,皆請在最後加入換行。

此外,在 $40\%$ 的測試資料中,長方形頂點的座標在 $0$ 以上 $100$ 以下,其中的 $1/2$ 為僅求面積的問題。而且,全部測試資料的 $1/2$ 為僅求面積的問題。

範例 1

範例輸入 1

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

範例輸出 1

29

範例 2

範例輸入 2

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

範例輸出 2

29
38

範例 3

範例輸入 3

2 2
0 0 8 9
0 0 9 8

範例輸出 3

80
36

範例 4

範例輸入 4

3 2
2 2 8 8
3 0 4 9
5 0 7 9

範例輸出 4

45
36

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.