알고리즘
[C++] 백준 2563번 색종이
J3SUNG
2019. 9. 19. 02:19
728x90
색종이의 총 넓이를 구하는 문제입니다.
가로 세로 전체 크기만큼의 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;
}