※ 1018 체스판 다시 칠하기
https://www.acmicpc.net/problem/1018
문제 해결 TIP
입력으로 주어진 맵(그래프)에서 8x8 크기로 자른 후, 가능한 두 가지 맵(그래프)과 비교하는 문제이다. 가능한 두 가지 그래프는 다음과 같다. 두 그래프와 동시에 비교해가며, 첫번째 그림과 다를 경우 count_1에 1씩 추가, 두번째 그림과 다를 경우 count_2에 1씩을 추가해준다. 이후 최값을 출력한다.
전체 코드
N, M = map(int,input().split())
graph = []
answer = []
for i in range(N):
graph.append(list(map(str,input())))
for i in range(N-7):
for j in range(M-7):
count_1 = 0
count_2 = 0
#8x8 크기로 자르기
for a in range(i,i+8):
for b in range(j,j+8):
if (a+b)%2 == 0:
#graph1과 다르다면
if graph[a][b] != 'B':
count_1 += 1
#graph2와 다르다면
if graph[a][b] != 'W':
count_2 += 1
else:
#graph1과 다르다면
if graph[a][b] != 'W':
count_1 += 1
#graph2와 다르다면
if graph[a][b] != 'B':
count_2 += 1
answer.append(count_1)
answer.append(count_2)
print(min(answer))
'Python > 브루트 포스' 카테고리의 다른 글
99클럽 코테 스터디 11일차 TIL + 백준 1018 체스판 다시 칠하기 (파이썬) (0) | 2025.02.03 |
---|---|
[Algorithm] 백준 14620 꽃길 | 파이썬 (브루트포스) (1) | 2024.09.21 |
[Algorithm] 백준 2309 일곱 난쟁이 | 파이썬 (0) | 2024.08.09 |
[Algorithm] 백준 1436 영화감독 숌 | 파이썬 (0) | 2024.08.07 |
[Algorithm] Brute Force(브루트 포스) (1) | 2024.01.05 |
댓글