728x90
반응형
포인트
- Brutal Force로 모든 케이스를 계산함
#include <stdio.h>
typedef signed long int int32_t;
typedef char char_t;
int32_t GetNeedColorChangeNumber(int32_t s32InitColumnIdx, int32_t s32InitRowIdx, char_t(*parchBadookPan)[50]);
int main()
{
const int32_t s32ChessPanSize = 8;
int32_t s32NumOfRow = 0, s32NumOfColumn = 0;
char_t archBadookPan[50][50] = { 0 };
int32_t s32NumOfColumnCase = 0, s32NumOfRowCase = 0;
int32_t s32NumOfTotalSearchCase = 0;
int32_t s32minNum = 999;
int32_t s32NumOfNeedChangeColor = 0;
// 입력
scanf("%d", &s32NumOfRow);
scanf("%d", &s32NumOfColumn);
for (int32_t s32j = 0; s32j != s32NumOfRow; ++s32j)
{
for (int32_t s32i = 0; s32i != s32NumOfColumn; ++s32i)
{
scanf("%c", &archBadookPan[s32j][s32i]);
if (archBadookPan[s32j][s32i] == '\n')
{
scanf("%c", &archBadookPan[s32j][s32i]);
}
else
{
// Do Nothing
}
}
}
// Main
s32NumOfColumnCase = s32NumOfColumn - s32ChessPanSize + 1;
s32NumOfRowCase = s32NumOfRow - s32ChessPanSize + 1;
s32NumOfTotalSearchCase = s32NumOfRowCase * s32NumOfColumnCase;
// Search All case - brutal force
for (int32_t s32RowIdx = 0; s32RowIdx != s32NumOfRowCase; ++s32RowIdx)
{
for (int32_t s32ColumnIdx = 0; s32ColumnIdx != s32NumOfColumnCase; ++s32ColumnIdx)
{
s32NumOfNeedChangeColor = GetNeedColorChangeNumber(s32ColumnIdx, s32RowIdx, archBadookPan);
if (s32NumOfNeedChangeColor < s32minNum)
{
s32minNum = s32NumOfNeedChangeColor;
}
else
{
// Do Nothing
}
}
}
printf("%d \n", s32minNum);
return 0;
}
int32_t GetNeedColorChangeNumber(
int32_t s32InitColumnIdx,
int32_t s32InitRowIdx,
char_t (*parchBadookPan)[50]
)
{
const int32_t s32ChessPanSize = 8;
int32_t s32NeedChangeInitB = 0, s32NeedChangeInitW = 0;
int32_t s32Cnt = 0;
int32_t s32RetVal = 0;
for (int32_t s32RowIdx = 0; s32RowIdx != s32ChessPanSize; ++s32RowIdx)
{
for (int32_t s32ColumnIdx = 0; s32ColumnIdx != s32ChessPanSize; ++s32ColumnIdx)
{
// Init Start B Case
if ((s32RowIdx % 2) == 0)
{
if ((s32Cnt % 2) == 0)
{
if (parchBadookPan[s32InitRowIdx + s32RowIdx][s32InitColumnIdx + s32ColumnIdx] == 'W')
{
++s32NeedChangeInitB;
}
else
{
// Do Nothing
}
}
else
{
if (parchBadookPan[s32InitRowIdx + s32RowIdx][s32InitColumnIdx + s32ColumnIdx] == 'B')
{
++s32NeedChangeInitB;
}
else
{
// Do Nothing
}
}
}
else
{
if ((s32Cnt % 2) == 0)
{
if (parchBadookPan[s32InitRowIdx + s32RowIdx][s32InitColumnIdx + s32ColumnIdx] == 'B')
{
++s32NeedChangeInitB;
}
else
{
// Do Nothing
}
}
else
{
if (parchBadookPan[s32InitRowIdx + s32RowIdx][s32InitColumnIdx + s32ColumnIdx] == 'W')
{
++s32NeedChangeInitB;
}
else
{
// Do Nothing
}
}
}
// Init Start W Case
if ((s32RowIdx % 2) == 0)
{
if ((s32Cnt % 2) == 0)
{
if (parchBadookPan[s32InitRowIdx + s32RowIdx][s32InitColumnIdx + s32ColumnIdx] == 'B')
{
++s32NeedChangeInitW;
}
else
{
// Do Nothing
}
}
else
{
if (parchBadookPan[s32InitRowIdx + s32RowIdx][s32InitColumnIdx + s32ColumnIdx] == 'W')
{
++s32NeedChangeInitW;
}
else
{
// Do Nothing
}
}
}
else
{
if ((s32Cnt % 2) == 0)
{
if (parchBadookPan[s32InitRowIdx + s32RowIdx][s32InitColumnIdx + s32ColumnIdx] == 'W')
{
++s32NeedChangeInitW;
}
else
{
// Do Nothing
}
}
else
{
if (parchBadookPan[s32InitRowIdx + s32RowIdx][s32InitColumnIdx + s32ColumnIdx] == 'B')
{
++s32NeedChangeInitW;
}
else
{
// Do Nothing
}
}
}
++s32Cnt;
}
}
if (s32NeedChangeInitB > s32NeedChangeInitW)
{
s32RetVal = s32NeedChangeInitW;
}
else
{
s32RetVal = s32NeedChangeInitB;
}
return s32RetVal;
}
728x90
반응형
'코딩 문제' 카테고리의 다른 글
[LeetCode] 876. Middle of the Linked List, C (0) | 2022.12.28 |
---|---|
[LeetCode] 1342 Number of Steps to Reduce a Number to Zero, C (0) | 2022.12.28 |
[백준] 유기농 배추, 1012, C (0) | 2022.11.28 |
[백준] 다리놓기, 1010, C (0) | 2022.11.25 |
[백준] A/B, 1008, C (0) | 2022.11.22 |