-
[백준] 1018 - 체스판 다시 칠하기(실버 4)알고리즘 문제/다시 풀어볼 것 2022. 10. 10. 20:35
https://www.acmicpc.net/problem/1018
2트
1트
시간: 50분 걸림
고칠 점: 읽기 쉬운 코드를 짠다는 핑계로 코드가 길어짐. 함수가 많아짐.from typing import List class Point: def __init__(self, x, y): self.__x = x self.__y = y @property def x(self): return self.__x @property def y(self): return self.__y def get_repaint_num_with_one_letter(target_board: List[str], cell_value: List[str], start: Point): count = 0 s_row = start.x s_col = start.y for row in range(s_row, s_row + 8): row_idx = row - s_row now = cell_value[row_idx % 2] for col in range(s_col, s_col + 8): col_idx = col - s_col cell = target_board[row][col] if cell != now: count += 1 now = cell_value[(row_idx + col_idx + 1) % 2] return count def get_repaint_num_with_both(target_board: List[str], start: Point): cell_value = ["B", "W"] count_with_x = get_repaint_num_with_one_letter(target_board, cell_value, start) cell_value = ["W", "B"] count_with_y = get_repaint_num_with_one_letter(target_board, cell_value, start) return min(count_with_x, count_with_y) row, col = map(int, input().split()) board = list() for _ in range(row): board.append(input()) result = 987654321 for start_col in range(col - 8 + 1): for start_row in range(row - 8 + 1): start = Point(start_row, start_col) now_result = get_repaint_num_with_both(board, start) result = min(result, now_result) print(result)
'알고리즘 문제 > 다시 풀어볼 것' 카테고리의 다른 글
[백준] 4153 - 직각삼각형 (0) 2022.10.17 [백준] 2609 - 최대공약수와 최소공배수(브론즈 1) (1) 2022.10.13 [백준] 2164 - 카드2(실버 4) (1) 2022.10.13 [백준] 1920 - 수 찾기(실버 4) (0) 2022.10.11 [백준] 1259 - 팰린드롬수(브론즈 1) (0) 2022.10.11