#include <stdio.h>
int tc;
int map[10][10];
const int dx[8] = { -1,-1,-1,0,0,1,1,1 };
const int dy[8] = { -1,0,1,-1,1,-1,0,1 };
const int WHITE = 2;
const int BLACK = 1;
const int NOT = 0;
const int TRUE = 1;
const int FLASE = 0;
int mapSize;
void put(int y, int x, int color)
{
int opColor;
if (color == BLACK)
opColor = WHITE;
else
opColor = BLACK;
int cnt = 0;
int dirY;
int dirX;
int changeFlag = 0;
for (int z = 0; z < 8; z++) {
dirY = y + dy[z];
dirX = x + dx[z];
changeFlag = 0;
// 한칸 이동한 방향이 반대색이고, 무엇인가 놓여져 있으면,
for (cnt = 0; map[dirY][dirX] == opColor && map[dirY][dirX] != NOT; dirY += dy[z], dirX += dx[z]) {
cnt++;
if (map[dirY + dy[z]][dirX + dx[z]] == color) // 자신의 색깔의 돌을 만날 때까지 이동함
{
for (int n = 0; n < cnt; n++, dirY -= dy[z], dirX -= dx[z])
{
map[dirY][dirX] = color;
changeFlag = 1;
}
}
if (changeFlag == 1)
break;
}
}
}
int main()
{
freopen("input.txt", "r", stdin);
scanf("%d", &tc);
int M;
for (int testCase = 1; testCase <= tc; testCase++)
{
scanf("%d %d", &mapSize, &M);
int y, x, color;
int black = 0;
int white = 0;
for (int y = 0; y <= 9; y++)
{
for (int x = 0; x <= 9; x++)
{
map[y][x] = NOT;
}
}
map[mapSize / 2][mapSize / 2] = WHITE;
map[mapSize / 2][mapSize / 2 + 1] = BLACK;
map[mapSize / 2 + 1][mapSize / 2] = BLACK;
map[mapSize / 2 + 1][mapSize / 2 + 1] = WHITE;
for (int j = 0; j < M; j++)
{
scanf("%d %d %d", &y, &x, &color);
map[y][x] = color;
put(y, x, color);
}
for (int y = 1; y <= mapSize; y++)
{
for (int x = 1; x <= mapSize; x++)
{
if (map[y][x] == BLACK)
black++;
else if (map[y][x] == WHITE)
white++;
}
}
printf("%d %d\n", black, white);
}
return 0;
}
댓글