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())
arr = [list(map(str,input())) for _ in range(n)]
result = []
for i in range(n-7):
for j in range(m-7):
idx1=0 #'W'๋ก ์์ํ๋ ๊ฒฝ์ฐ
idx2=0 #'B'๋ก ์์ํ๋ ๊ฒฝ์ฐ
for a in range(i,i+8):
for b in range(j,j+8):
if (a+b)%2==0: #ํ+์ด ์ง์์ผ๋
if arr[a][b] != 'W': #W๋ก ์์ํ ๋ W๋ ์๋ ํ+์ด์ด ์ง์
idx1+=1 #๋ฐ๋ผ์ W๊ฐ ์๋ ๊ฒ์ ๋ฐ๊ฟ์ค์ผํ์ idx1+=1
if arr[a][b] != 'B': #B๋ก ์์ํ ๋ B๋ ์๋ ํ+์ด์ด ์ง์
idx2+=1 #๋ฐ๋ผ์ B๊ฐ ์๋ ๊ฒ์ ๋ฐ๊ฟ์ค์ผํ์ idx2+=1
else:#ํ+์ด ํ์์ผ๋
if arr[a][b] != 'B':
idx1+=1
if arr[a][b] != 'W':
idx2+=1
result.append(min(idx1,idx2)) # ์์์ ์ด 'W'์ผ๋์ 'B'์ผ ๋ ์ค ๋ฐ๊ฟ ๊ฒ์ด ์ ์๊ฒ์ reuslt๋ฐฐ์ด์ ์ถ๊ฐ!
print(min(result)) #์ต์๋ก ๋ฐ๊พธ๋ ๊ฒ์ ๊ฐฏ์ ์ถ๋ ฅ
'Problem Solving > BAEKJOON' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[baekjoon]python #10816 ์ซ์ ์นด๋ 2 (0) | 2022.06.03 |
---|---|
[baekjoon]python #1920 ์ ์ฐพ๊ธฐ (0) | 2022.06.03 |
[baekjoon]python #2231 ๋ถํดํฉ (0) | 2022.06.03 |
[baekjoon]python #1929 ์์ ๊ตฌํ๊ธฐ (0) | 2022.06.03 |
[baekjoon]python #2798 ๋ธ๋์ญ (0) | 2022.06.03 |
๋๊ธ