-
[백준] 1018번_체스판다시칠하기Study/알고리즘 2020. 1. 28. 21:34
문제 링크 : https://www.acmicpc.net/problem/1018
1018번: 체스판 다시 칠하기
첫째 줄에 N과 M이 주어진다. N과 M은 8보다 크거나 같고, 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 보드의 각 행의 상태가 주어진다. B는 검은색이며, W는 흰색이다.
www.acmicpc.net
n,m = map(int,input().split()) board = [list(input()) for _ in range(n)] color = n*m for i in range(n-7): for j in range(m-7): #흰 w=0 for k in range(i,i+8): for s in range(j,j+8): if (k%2==0 and s%2==0) or (k%2==1 and s%2==1): if board[k][s] == "B": w += 1 elif (k%2==0 and s%2==1) or (k%2==1 and s%2==0): if board[k][s] == "W": w += 1 #검 b=0 for k in range(i,i+8): for s in range(j,j+8): if (k%2==0 and s%2==0) or (k%2==1 and s%2==1): if board[k][s] == "W": b += 1 elif (k%2==0 and s%2==1) or (k%2==1 and s%2==0): if board[k][s] == "B": b += 1 #최소 color = min(color,w,b) print(color)
왜 이렇게 오래걸렸지...
'Study > 알고리즘' 카테고리의 다른 글
[백준] 15649번_N과M(1) (0) 2020.01.29 [백준] 1051번_숫자정사각형 (0) 2020.01.28 [백준] 1436번_영화감독숌 (0) 2020.01.28 [백준] 7568번_덩치 (0) 2020.01.28 [백준] 2231번_분해합 (0) 2020.01.28