ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 1018 체스판 다시 칠하기
    Computer Science/백준 Boj 2023. 10. 19. 16:13
    #include "pch.h"
    
    char A[50][50];
    int N, M;
    
    int paint_cnt = 0;
    
    char WB[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 BW[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 IsWB(int x, int y)
    {
    	int result = 0;
    
    	for (int i = y; i < y + 8; ++i)
    	{
    		for (int j = x; j < x + 8; ++j)
    		{
    			if (A[i][j] != WB[i - y][j - x])
    				++result;
    		}
    	}
    	return result;
    }
    
    int IsBW(int x, int y)
    {
    	int result = 0;
    
    	for (int i = y; i < y + 8; ++i)
    	{
    		for (int j = x; j < x + 8; ++j)
    		{
    			if (A[i][j] != BW[i - y][j - x])
    				++result;
    		}
    	}
    	return result;
    }
    int main()
    {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    
    	cin >> N >> M;
    
    	for (int i = 0; i < N; ++i)
    	{
    		for (int j = 0; j < M; ++j)
    		{
    			cin >> A[i][j];
    		}
    	}
    
    	int answer = 50 * 50;
    
    	for (int i = 0; i < N ; ++i)
    	{
    		for (int j = 0; j < M; ++j)
    		{
    			int WBCnt = IsWB(j, i);
    			int BWCnt = IsBW(j, i);
    
    			int cnt = min(WBCnt, BWCnt);
    
    			answer = min(cnt, answer);
    		}
    	}
    
    	cout << answer;
    	return 0;
    }

    'Computer Science > 백준 Boj' 카테고리의 다른 글

    백준 1202 보석 도둑  (0) 2023.10.19
    백준 1158 요세푸스 문제  (0) 2023.10.19
    7.1 QuickSort  (0) 2023.09.06
    [백준]c++/구현/2573  (0) 2023.03.04
    백준/C++/구현/16234  (0) 2023.03.02
Designed by Tistory.