백준 - 모노미노도미노 2 (20061 번)

well-life-gm·2021년 11월 12일
0

백준 삼성

목록 보기
17/23

백준 - 모노미노도미노 2 (20061 번)

어려운 구현은 딱히 없이 단순 시뮬레이션만 수행해주면 된다.

희미한 파랑색 공간은 (0~4행 x 4~5열), 희미한 초록생 공간은 (4~5행 x 0~4열)으로 생각해서 풀어주면 10x10 맵에 바로 매핑이 된다.
즉, 파랑색 공간은 (0~4행 x 4~9열), 초록색 공간은 (4~9행 x 0~4열)으로 생각하면 된다.

Map의 크기가 10 by 10으로 고정되어 있기 때문에 Input 값에 따라서 참고해야하는 Index가 변경되는 등의 복잡한 요소도 없다.

코드는 아래와 같다.

#include <cstdio>
#include <iostream>

using namespace std;

int n;
int block_info[10002][3];
int map[10][10];

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; i++) 
		for(int j = 0 ; j < 3; j++)
			cin >> block_info[i][j];

	int answer = 0;
	for (int i = 0; i < n; i++) {
		int block_type = block_info[i][0];
		int row = block_info[i][1];
		int col = block_info[i][2];
		if (block_type == 1) {
			int ncol = col;
			while (1) {
				ncol += 1;
				if (ncol > 9)
					break;
				if (map[row][ncol] == 1) 
					break;
			}
			map[row][ncol - 1] = 1;

			int nrow = row;
			while (1) {
				nrow += 1;
				if (nrow > 9)
					break;
				if (map[nrow][col] == 1)
					break;
			}
			map[nrow - 1][col] = 1;
		}
		else if (block_type == 2) {
			int ncol = col + 1;
			while (1) {
				ncol += 1;
				if (ncol > 9)
					break;
				if (map[row][ncol] == 1)
					break;
			}
			map[row][ncol - 1] = 1;
			map[row][ncol - 2] = 1;

			int nrow = row;
			while (1) {
				nrow += 1;
				if (nrow > 9)
					break;
				if (map[nrow][col] == 1 || map[nrow][col + 1] == 1)
					break;
			}
			map[nrow - 1][col] = 1;
			map[nrow - 1][col + 1] = 1;
		}
		else if (block_type == 3) {
			int ncol = col;
			while (1) {
				ncol += 1;
				if (ncol > 9)
					break;
				if (map[row][ncol] == 1 || map[row + 1][ncol] == 1)
					break;
			}
			map[row][ncol - 1] = 1;
			map[row + 1][ncol - 1] = 1;

			int nrow = row + 1;
			while (1) {
				nrow += 1;
				if (nrow > 9)
					break;
				if (map[nrow][col] == 1)
					break;
			}
			map[nrow - 1][col] = 1;
			map[nrow - 2][col] = 1;
		}

		for (int i = 9; i >= 6; i--) {
			if (map[0][i] == 1 && map[1][i] == 1 && map[2][i] == 1 && map[3][i] == 1) {
				for (int j = i; j >= 4; j--) {
					map[0][j] = map[0][j - 1];
					map[1][j] = map[1][j - 1];
					map[2][j] = map[2][j - 1];
					map[3][j] = map[3][j - 1];
				}
				i++;
				answer++;
			}
		}
		
		for (int i = 9; i >= 6; i--) {
			if (map[i][0] == 1 && map[i][1] == 1 && map[i][2] == 1 && map[i][3] == 1) {
				for (int j = i; j >= 4; j--) {
					map[j][0] = map[j - 1][0];
					map[j][1] = map[j - 1][1];
					map[j][2] = map[j - 1][2];
					map[j][3] = map[j - 1][3];
				}
				i++;
				answer++;
			}
		}

		int shift_cnt = 0;
		for (int i = 5; i >= 4; i--) 
			if (map[0][i] == 1 || map[1][i] == 1 || map[2][i] == 1 || map[3][i] == 1) 
				shift_cnt++;
		for (int s = 0; s < shift_cnt; s++) 
			for (int i = 9; i >= 4; i--) {
				map[0][i] = map[0][i - 1];
				map[1][i] = map[1][i - 1];
				map[2][i] = map[2][i - 1];
				map[3][i] = map[3][i - 1];
			}
		shift_cnt = 0;
		for (int i = 5; i >= 4; i--)
			if (map[i][0] == 1 || map[i][1] == 1 || map[i][2] == 1 || map[i][3] == 1)
				shift_cnt++;

		for (int s = 0; s < shift_cnt; s++)
			for (int i = 9; i >= 4; i--) {
				map[i][0] = map[i - 1][0];
				map[i][1] = map[i - 1][1];
				map[i][2] = map[i - 1][2];
				map[i][3] = map[i - 1][3];
			}
	}
	int num_of_tile = 0;
	for (int i = 6; i < 10; i++) {
		for (int j = 0; j < 4; j++) {
			num_of_tile += map[i][j];
			num_of_tile += map[j][i];
		}
	}
	cout << answer << "\n" << num_of_tile << "\n";
	
	return 0;
}
profile
내가 보려고 만든 블로그

0개의 댓글

관련 채용 정보