[백준] 2563번 색종이 / C++
#문제
#풀이
#include <iostream>
using namespace std;
int paper[101][101] = { 0 };
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
int T;
cin >> T;
while (T--)
{
int x, y;
cin >> x >> y;
for (int i = x; i < x + 10; ++i)
{
for (int j = y; j < y + 10; ++j)
{
paper[i][j] = 1;
}
}
}
int cnt = 0;
for (int i = 1; i < 101; ++i)
{
for (int j = 1; j < 101; ++j)
{
if (paper[i][j] == 1)
{
cnt++;
}
}
}
cout << cnt;
return 0;
}
#정리
크기가 101*101인 배열을 하나 만들고 0으로 초기화한다. T번 색종이의 좌측 하단 x, y 좌표를 입력 받는데, 입력 받을 때마다 x, y 각각 +10 만큼의 좌표 값을 1로 바꿔준다. 아무리 많이 중복되어도 1에서 숫자가 바뀌지 않기 때문에 연산이 끝난 후 카운트하여 출력하면 된다.
Enjoy Reading This Article?
Here are some more articles you might like to read next: