문제 링크: https://www.acmicpc.net/problem/15592
15592번: Blocked Billboard II
The first line of input contains four space-separated integers: $x_1$ $y_1$ $x_2$ $y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are the coordinates of the lower-left and upper-right corners of the lawnmower billboard in Bessie's 2D field of view. The next lin
www.acmicpc.net
처음 입력받은 직사각형을 먼저 1로 배열에 입력받고, 다음 직사각형을 2로 같은 배열에 입력받음. (따라서 2가 1을 덮을수도 있음.) 1을 모두 가리기 위한 직사각형의 넓이가 필요하므로, 배열에 여전히 남아있는 1의 가장 왼쪽, 오른쪽, 위, 아래 좌표를 이용해서 답을 구하면 됨.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <bits/stdc++.h>
using namespace std;
int field[2001][2001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n = 1;
for(int t = 0; t < 2; t++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1 += 1000, y1 += 1000, x2 += 1000, y2 += 1000;
for(int i = y1; i < y2; i++) for(int j = x1; j < x2; j++)
field[i][j] = n;
n++;
}
int minx = 1e9, miny = 1e9, maxx = -1e9, maxy = -1e9;
for(int i = 0; i <= 2000; i++) for(int j = 0; j <= 2000; j++) {
if(field[i][j] == 1) {
minx = min(minx, j);
miny = min(miny, i);
maxx = max(maxx, j);
maxy = max(maxy, i);
}
}
if(minx == 1e9) cout << 0 << '\n';
else cout << (maxx - minx + 1) * (maxy - miny + 1) << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Bronze' 카테고리의 다른 글
백준 15594 Out of Place (USACO January 2018 Bronze 3번) (0) | 2020.03.06 |
---|---|
백준 15593 Lifeguards (USACO January 2018 Bronze 2번) (0) | 2020.03.06 |
백준 15464 The Bovine Shuffle (USACO December 2017 Bronze 2번) (0) | 2020.03.03 |
백준 15463 Blocked Billboard (USACO December 2017 Bronze 1번) (0) | 2020.03.03 |
백준 14531 Bovine Genomics (USACO US Open 2017 Bronze 2번) (0) | 2020.03.01 |