끄적끄적 코딩
article thumbnail
Published 2019. 9. 19. 02:19
[C++] 백준 2563번 색종이 알고리즘

색종이의 총 넓이를 구하는 문제입니다.

가로 세로 전체 크기만큼의 2차원 배열을 만들고
x, y를 입력받고 x +10, y + 10까지를 전부 1로 바꿔줍니다.
이를 반복하고 마지막에 1로 되어있는 개수를 세어었습니다.

 

#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

int main(int argc, char * argv[])
{
	int n;
	int x, y;
	int count = 0;
	int map[110][110];
	
	cin >> n;

	memset(map, 0, sizeof(map));

	while (n--) {
		cin >> x >> y;

		for (int i = x; i < x + 10; ++i) {
			for (int j = y; j < y + 10; ++j) {
				map[i][j] = 1;
			}
		}
	}

	for (int i = 0; i <= 100; ++i) {
		for (int j = 0; j <= 100; ++j) {
			if (map[i][j] == 1) {
				++count;
			}
		}
	}

	cout << count << endl;

	return 0;
}

'알고리즘' 카테고리의 다른 글

[C++] 백준 13458번 시험 감독  (0) 2019.09.19
[C++] 백준 2607번 비슷한 단어  (0) 2019.09.19
[C++] 백준 10807번 개수 세기  (0) 2019.09.19
[C++] 백준 2309번 일곱 난쟁이  (0) 2019.09.19
[C++] 백준 9660번 돌 게임 6  (0) 2019.09.18

검색 태그