#include <stdio.h>
int map[51][51] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 2, 1, 0, 0, 0, 0, 0, 2, 3},
{0, 3, 0, 2, 0, 1, 2, 1, 0, 1, 2},
{0, 4, 0, 1, 0, 1, 2, 3, 2, 0, 1},
{0, 3, 2, 0, 0, 0, 1, 2, 4, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 5, 3, 0},
{0, 0, 1, 2, 1, 0, 1, 5, 4, 3, 0},
{0, 0, 1, 2, 3, 1, 3, 6, 2, 1, 0},
{0, 0, 0, 3, 4, 8, 9, 7, 5, 0, 0},
{0, 0, 0, 0, 3, 7, 8, 6, 0, 1, 2},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}
};
int book[51][51] = {0};
int sum = 0;
int next[4][2] = {
{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
void dfs(int x, int y,int color)
{
int k;
int tx, ty;
map[x][y] = color;
for (k = 0; k <= 3; k++)
{
tx = x + next[k][0];
ty = y + next[k][1];
if (tx < 1 || tx > 10 || ty < 1 || ty > 10)
continue;
if (map[tx][ty] > 0 && book[tx][ty] == 0)
{
sum++;
book[tx][ty] = 1;
dfs(tx, ty, color);
寻找一个图中独立子图的个数
最新推荐文章于 2023-01-08 22:02:05 发布