[백준] 1018번: 체스판 다시 칠하기

짜장범벅·2022년 8월 3일
0

백준

목록 보기
16/26

1 문제

배열 중 8*8 배열을 추출해, 특정 색이 번갈가가며 있지 않은 경우의 수 count

2 Idea

모든 Case 체크

3 Code

// link: https://www.acmicpc.net/problem/1018

#include <iostream>
#include <vector>

typedef enum{
    black = 0,
    white = 1,
} color;

int MakeChessPan(const std::vector<std::vector<color>>& v, const int N, const int M){
    int ChessPan = N*M+1;
    
    for (int i_start=0; i_start<N-7; ++i_start){
        for (int j_start=0; j_start<M-7; ++j_start){
            for (const auto startColor : {black, white}){
                int count = 0;

                for (int i=0; i<8; ++i){
                    for (int j=0; j<8; ++j){
                        if (((i+j)%2==0) && (v[i_start+i][j_start+j] != startColor)){
                            ++count;
                        }
                        else if (((i+j)%2==1) && (v[i_start+i][j_start+j] == startColor)){
                            ++count;
                        }
                    }
                }

                if (count < ChessPan){
                    ChessPan = count;
                }
            }
        }
    }

    return ChessPan;
}

int main(){
    int N = 0;
    int M = 0;
    std::cin >> N >> M;

    std::vector<std::vector<color>> v(N, std::vector<color>(M, black));
    for (int i=0; i<N; ++i){
        std::string temp;
        std::cin >> temp;

        for (int j=0; j<M; ++j){
            if (temp[j] == 'W'){
                v[i][j] = white;
            }
        }
    }

    std::cout << MakeChessPan(v, N, M) << std::endl;
}
profile
큰일날 사람

0개의 댓글