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.