VioletaBabel
1018번: 체스판 다시 칠하기 본문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include<cstdio> int main() { int n, m, ans = 50*50; char chess[50][51]; scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) scanf("%s", &chess[i]); for (int ii = 0; ii <= n-8; ++ii) for (int jj = 0, nowans; jj <= m-8; ++jj) { nowans = 64; for (int i = 0+ii; i < 8+ii; i+=2) for (int j = 0+jj; j < 8+jj; j+=2) { if (chess[i][j] == 'W') --nowans; if (chess[i][j+1] == 'B') --nowans; } for (int i = 1 + ii; i < 8 + ii; i += 2) for (int j = 0 + jj; j < 8 + jj; j+=2) { if (chess[i][j] == 'B') --nowans; if (chess[i][j+1] == 'W') --nowans; } ans = (ans < nowans) ? ans : nowans; nowans = 64; for (int i = 0 + ii; i < 8 + ii; i += 2) for (int j = 0 + jj; j < 8 + jj; j += 2) { if (chess[i][j] == 'B') --nowans; if (chess[i][j+1] == 'W') --nowans; } for (int i = 1 + ii; i < 8 + ii; i += 2) for (int j = 0 + jj; j < 8 + jj; j += 2) { if (chess[i][j] == 'W') --nowans; if (chess[i][j+1] == 'B') --nowans; } ans = (ans < nowans) ? ans : nowans; } printf("%d", ans); } | cs |
'백준 > 백준-C++' 카테고리의 다른 글
1748번: 수 이어 쓰기 1 (0) | 2018.03.15 |
---|---|
1966번: 프린터 큐 (0) | 2018.03.15 |
2503번: 숫자 야구 (0) | 2018.03.13 |
2448번: 별찍기 - 11 (0) | 2018.02.14 |
2446번: 별찍기 - 9 (0) | 2018.02.06 |
Comments