[BOJ]2669번: 직사각형 네개의 합집합의 면적 구하기
접근
처음에 접근을 무작정 빼고 더하고... 하려고 했으나 감히 그 행동을 하지 못하겠어서 질문 검색을 해봤습니다 ㅠㅠ
풀이
메모리를 포기하고 정신을 챙겨간다! 100x100의 배열을 만들고 그 칸들을 채워나가는 방식으로 문제를 풀어봤습니다.
코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h>
int main()
{
int square[101][101], cnt = 0, x1, x2, y1, y2;
for (int i = 0; i < 101; i++) {
for (int j = 0; j < 101; j++) {
square[i][j] = 0;
}
}
for (int i = 0; i < 4; i++) {
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
for (int j = x1; j < x2; j++) {
for (int k = y1; k < y2; k++) {
if (!square[j][k]) {
square[j][k] = 1;
cnt++;
}
}
}
}
printf("%d\n", cnt);
return 0;
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int square[101][101], cnt = 0, x1, x2, y1, y2; | |
for (int i = 0; i < 101; i++) { | |
for (int j = 0; j < 101; j++) { | |
square[i][j] = 0; | |
} | |
} | |
for (int i = 0; i < 4; i++) { | |
scanf("%d %d %d %d", &x1, &y1, &x2, &y2); | |
for (int j = x1; j < x2; j++) { | |
for (int k = y1; k < y2; k++) { | |
if (!square[j][k]) { | |
square[j][k] = 1; | |
cnt++; | |
} | |
} | |
} | |
} | |
printf("%d\n", cnt); | |
return 0; | |
} |
'온라인저지' 카테고리의 다른 글
[BOJ] 1932번: 숫자삼각형 (0) | 2018.02.03 |
---|---|
[BOJ]1978번: 소수 찾기 (0) | 2018.02.02 |
[BOJ]2193번: 이친수 (0) | 2018.02.01 |
[BOJ]2667번: 단지번호붙이기 (0) | 2018.01.25 |
[BOJ] 1002번 : 터렛 (0) | 2017.11.16 |
[BOJ] 1260번: DFS와 BFS (0) | 2017.11.04 |