0是水,1是土。水应该是陆地的三倍。需要计算单个岛屿的数量。单个岛屿被认为是 1,四周被 0 包围。
11000
00010
10000
注意:站在角落的单个岛屿不会四面被水包围,检查时要记住这一点,以免超出阵列。
请帮帮我。我不知道如何计算它们。
这是它的开始方式:
#include <iostream>
#include <time.h>
using namespace std;
void main()
{
srand(time(0));
rand();
const int n = 12;
int mas[n][n] = {};
int x, y, kol_vo = 0;
while (kol_vo < 36)
{
x = rand() % n;
y = rand() % n;
if (mas[x][y] == 0)
{
mas[x][y] = 1;
kol_vo++;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << mas[i][j] << " ";
}
cout << endl;
}
system("pause");
}