# SRM 593 Div1 L1：HexagonalBoard，用染色法判断无向图是否为二分图

#include <algorithm>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>

using namespace std;

/*************** Program Begin **********************/
int dx[] = {0, -1, -1, 0, 1, 1}, dy[] = {-1, 0, 1, 1, 0, -1};
class HexagonalBoard {
private:
vector <string> board;
int color[50][50];
int result, N;
public:
void DFS(int x, int y, int c)
{
int nx, ny;
if ('X' == board[x][y] && -1 == color[x][y]) {
color[x][y] = c;
result = max(result, 1);
for (int i = 0; i < 6; i++) {
nx = x + dx[i];
ny = y + dy[i];
if (nx < 0 || nx > N-1 || ny < 0 || ny > N-1) {
continue;
}
if ('X' == board[nx][ny]) {
result = max(result, 2);
DFS(nx, ny, !c);
if (c == color[nx][ny]) {
result = 3;
}
}
}
}
}

int minColors(vector <string> board)
{
this->board = board;
memset(color, -1, sizeof(color));
result = 0;
N = board.size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
DFS(i, j, 0);
}
}
return result;
}
};

/************** Program End ************************/


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120