BOJ 1018 체스판 다시 칠하기

1 개요[ | ]

BOJ 1018 체스판 다시 칠하기


2 같이 보기[ | ]

3 C++[ | ]

#include <iostream>
using namespace std;

int getResult(int n, int m, string* rows) {
    bool boards[2][50][50] = {0};
    int i, j;
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++) {
            if(rows[i][j] == 'W') boards[(i+j)%2][i][j] = 1;
            else boards[(i+j+1)%2][i][j] = 1;
        }
    }
    int count, wb, x, y;
    int min = 64;
    for(wb=0; wb<2; wb++) {
        for(x=0; x<n-7; x++) {
            for(y=0; y<m-7; y++) {
                count = 0;
                for(i=x; i<x+8; i++) {
                    for(j=y; j<y+8; j++) {
                        count += boards[wb][i][j];
                    }
                }
                if( count < min ) min = count;
            }
        }
    }
    return min;
}

int main() {
    int N, M;
    cin >> N >> M;
    string rows[50];
    for(int i=0; i<N; i++) {
        cin >> rows[i];
    }
    cout << getResult(N, M, rows) << '\n';
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}