[백준] #1018 체스판 다시 칠하기 python
2022. 12. 30. 13:53
https://www.acmicpc.net/problem/1018
1018번: 체스판 다시 칠하기
첫째 줄에 N과 M이 주어진다. N과 M은 8보다 크거나 같고, 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 보드의 각 행의 상태가 주어진다. B는 검은색이며, W는 흰색이다.
www.acmicpc.net
📕 설명 📕
하나씩 비교하는 brute-force로 풀이하였다.
사중 for문으로 구성 되었다.....
좀 더 간략한 방법을 찾아보자.
🧑🏻💻 나의 풀이 🧑🏻💻
N ,M = map(int, input().split())
black_and_white = []
for i in range(N):
black_and_white.append(input())
result = []
for x in range(N - 7):
for y in range(M - 7):
start_with_B = 0
start_with_W = 0
for i in range(8):
for j in range(8):
if (x+i + y+j) % 2 == 0:
if black_and_white[x+i][y+j] != "B":
start_with_W += 1
if black_and_white[x+i][y+j] != "W":
start_with_B += 1
else:
if black_and_white[x+i][y+j] != "W":
start_with_W += 1
if black_and_white[x+i][y+j] != "B":
start_with_B += 1
result.append(start_with_W)
result.append(start_with_B)
print(min(result))
'Programming > Algorithm' 카테고리의 다른 글
[백준] #14425 문자열 집합 python (0) | 2022.12.30 |
---|---|
[백준] #10815 숫자 카드 python (0) | 2022.12.30 |
[백준] #1436 영화감독 숌 python (0) | 2022.12.30 |
[백준] #7568 덩치 python (4) | 2022.12.28 |
[백준] #2231 분해합 python (0) | 2022.12.28 |