[백준 14600번] 샤워실 바닥 갈기 (Small) (C++)

2023. 10. 26. 11:20·PS/백준 알고리즘[BOJ]
728x90

이미지 예시

#include<iostream>
using namespace std;
int num;
int map[4][4];
bool check(int x1, int y1, int x2, int y2) {
	for (int i = x1; i < x2; i++) {
		for (int j = y1; j < y2; j++) {
			if (map[i-1][j-1] != 0) return false;
		}
	}
	return true;
}
void tromino(int s, int x, int y, int& t) {
	if (s == 0) return;
	int size = (1 <<s-1);
	num++;
	if (check(x, y, x + size, y + size) == true) map[x + size - 2][y + size - 2] = num;
	if (check(x + size, y, x + 2 * size, y + size) == true) map[x + size-1][y + size - 2] = num;
	if (check(x, y + size, x + size, y + 2 * size) == true) map[x + size - 2][y + size-1] = num;
	if (check(x + size, y + size, x + 2 * size, y + 2 * size) == true) map[x + size-1][y + size-1] = num;
	tromino(s - 1, x, y, num);
	tromino(s - 1, x+size, y, num);
	tromino(s - 1, x, y + size, num);
	tromino(s - 1, x + size, y + size, num);
}
int main(void) {
	int k, m, n;
	cin >> k >> m >> n;
	map[m-1][n-1] = -1;
	int siz = (1 << k);
	tromino(k, 1, 1, num);
	for (int i = siz-1; i >= 0; i--, cout<<"\n") {
		for (int j = 0; j<siz; j++, cout << " ") cout << map[j][i];
	}
	return 0;
}
728x90

'PS > 백준 알고리즘[BOJ]' 카테고리의 다른 글

[백준 14601] 샤워실 바닥 깔기 (Large)  (0) 2023.10.27
[백준 1629번] 곱셈 (C++)  (0) 2023.10.26
[백준 9920번] image (C++)  (0) 2023.10.21
[백준 10830번] 행렬 제곱 (C++)  (0) 2023.10.21
[백준 1780번] 종이의 개수 (C++)  (0) 2023.10.21
'PS/백준 알고리즘[BOJ]' 카테고리의 다른 글
  • [백준 14601] 샤워실 바닥 깔기 (Large)
  • [백준 1629번] 곱셈 (C++)
  • [백준 9920번] image (C++)
  • [백준 10830번] 행렬 제곱 (C++)
BE_개발자
BE_개발자
경이로운 BE 개발자가 되기 위한 프로그래밍 공부 기록장
    250x250
  • BE_개발자
    경이로운 개발일기
    BE_개발자
  • 전체
    오늘
    어제
    • 전체 보기 (213)
      • AI (1)
        • AI native (0)
        • Skill (0)
      • SpringBoot (4)
        • JPA (3)
        • Security (0)
        • 튜토리얼 (1)
        • 기타 (0)
      • Infra (0)
        • Docker (0)
        • AWS (0)
        • NCP (0)
        • GCP (0)
      • React (19)
      • 서버 (0)
      • Computer Science (16)
        • SW Engineering (10)
        • Data Base (2)
        • OS(운영 체제) (4)
      • Data science (0)
        • Probability & Random Variab.. (0)
        • Data Analysis(데이터 분석) (0)
      • 자료구조 | 알고리즘 (57)
        • 선형 자료구죠 (6)
        • 비선형 자료구조 (9)
        • 정렬(Sort) (3)
        • 탐색(Brute Force) (7)
        • 분할 정복(Devide Conquer) (3)
        • 동적 계획법 (6)
        • 탐욕(Greedy) (2)
        • 수학 (7)
        • 심화 알고리즘 (10)
      • PS (44)
        • 백준 알고리즘[BOJ] (38)
        • 프로그래머스[programmers] (3)
      • Dev tool (15)
        • 개발 도구 및 환경 (0)
        • vscode (3)
        • Git Hub (4)
        • Chrome 웹스토어 (5)
        • Python 전용 개발환경 (0)
      • 성장기록 (1)
      • 개인 project (14)
        • 홈페이지 만들기 (11)
        • 냉보미 (1)
      • STL(Standard Library) (9)
      • programming Language (1)
        • javascript (1)
      • 기타 (13)
        • html css (11)
      • (책, 글, 블로그)리뷰 (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 백준
    • Github
    • Notion
    • 서울과학기술대학교 학술동아리 EC
  • 공지사항

  • 인기 글

  • 태그

    비트마스킹
    그리디
    OS
    CS
    stl
    완전 탐색
    재귀함수
    DP
    stack
    백준
    BFS
    스택
    탐색
    C++
    이분 탐색
    스프링부트
    백트래킹
    괄호쌍
    PS
    브루트포스
    자료구조
    SW 공학
    알고리즘
    분할정복
    프론트엔드
    수학
    운영체제
    SW Engineering
    순열
    react
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
BE_개발자
[백준 14600번] 샤워실 바닥 갈기 (Small) (C++)
상단으로

티스토리툴바