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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | // 1018 체스판 다시 칠하기 #include <iostream> #include <algorithm> using namespace std; char origin_A[8][8] = { 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' }; char origin_B[8][8] = { 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' }; int compare_origin(char a[8][8], char b[8][8]) { int count = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (a[i][j] != b[i][j]) { count += 1; } } } return count; } int main() { int N; int M; cin >> N >> M; char in_chess[50][50]; int minimum[50][50]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> in_chess[i][j]; } } for (int i = 0; i <= N - 8; i++) { for (int j = 0; j <= M - 8; j++) { int count_A = 0; int count_B = 0; for (int k = 0; k < 8; k++) { for (int l = 0; l < 8; l++) { if (origin_A[k][l] != in_chess[i + k][j + l]) { count_A += 1; } if (origin_B[k][l] != in_chess[i + k][j + l]) { count_B += 1; } } } minimum[i][j] = count_A < count_B ? count_A : count_B; } } int min = minimum[0][0]; for (int i = 0; i <= N - 8; i++) { for (int j = 0; j <= M - 8; j++) { if (min > minimum[i][j]) { min = minimum[i][j]; } } } cout << min << endl; return 0; } | cs |
'프로그래밍 > 백준' 카테고리의 다른 글
2096 - 내려가기 (0) | 2018.10.03 |
---|---|
1003 피보나치수열 (0) | 2018.09.11 |
15552 빠른 A+B (0) | 2018.05.26 |
5622 다이얼 (0) | 2018.02.08 |
2908 상수 (0) | 2018.02.08 |