
안녕하세요 !
오늘은 백준 - 체스판 다시 칠하기 문제를 가지고 왔습니다.

문제를 해결한 방법을 간략히 적어보겠습니다.
- 입력 받는다.
- 맨 위쪽 위 칸이 검은색과 흰색 중 하나로 된 8x8 크기의 체스판을 각각 만든다.
- 입력받은 체스판에서 만들 수 있는 8x8 크기의 체스판의 맨 위쪽 위칸의 좌표를 구하고 좌표를 함수의 인자로 넘긴다.
- 검은색과 흰색 중 하나로 된 8x8 크기의 체스판과 입력받은 체스판을 8x8 크기로 잘라낸 체스판의 색이 다른 것을 카운트 한다.
- 색이 다른 것을 카운트한 것들 가운데 가장 작은 수를 구한다.
import sys num = list(map(int, sys.stdin.readline().strip().split())) map_1 = [] for i in range(num[0]): map_1.append(list(sys.stdin.readline().strip()))
map_compare_1 = [] map_compare_2 = [] for y in range(8): m_1 = [] m_2 = [] for x in range(8): if y%2 and x%2: m_1.append('W') m_2.append('B') elif y%2 and not x%2: m_1.append('B') m_2.append('W') elif not y%2 and x%2: m_1.append('B') m_2.append('W') elif not y%2 and not x%2: m_1.append('W') m_2.append('B') map_compare_1.append(m_1) map_compare_2.append(m_2)
count = [] for y in range(num[0] - 7): for x in range(num[1] - 7): return_cnt = compare(x, y, map_1) count += return_cnt
def compare(x, y, map_1): cnt = [0,0] for i in range(8): for j in range(8): if map_1[i+y][j+x] != map_compare_1[i][j]: cnt[0] += 1 elif map_1[i+y][j+x] != map_compare_2[i][j]: cnt[1] += 1 return cnt
print(min(count))
import sys
num = list(map(int, sys.stdin.readline().strip().split()))
map_1 = []
for i in range(num[0]):
map_1.append(list(sys.stdin.readline().strip()))
map_compare_1 = []
map_compare_2 = []
for y in range(8):
m_1 = []
m_2 = []
for x in range(8):
if y%2 and x%2:
m_1.append('W')
m_2.append('B')
elif y%2 and not x%2:
m_1.append('B')
m_2.append('W')
elif not y%2 and x%2:
m_1.append('B')
m_2.append('W')
elif not y%2 and not x%2:
m_1.append('W')
m_2.append('B')
map_compare_1.append(m_1)
map_compare_2.append(m_2)
def compare(x, y):
cnt = [0,0]
for i in range(8):
for j in range(8):
if map_1[i+y][j+x] != map_compare_1[i][j]:
cnt[0] += 1
elif map_1[i+y][j+x] != map_compare_2[i][j]:
cnt[1] += 1
return cnt
count = []
for y in range(num[0] - 7):
for x in range(num[1] - 7):
return_cnt = compare(x, y, map_1)
count += return_cnt
print(min(count))