#include <iostream>
#include <string>
#include <queue>
using namespace std;
struct point
{
int x;
int y;
int counts;
};
queue<point> ss;
point p_temp;
int nums = 0;
void dfs(int x,int y,char map[][9])
{
if (!ss.empty())
{
p_temp = ss.front();
ss.pop();
for (int i = p_temp.x-1; i <= p_temp.x + 1; i++)
{
if (i >= 0 && i < 9)
{
for (int j = p_temp.y - 1; j <= p_temp.y + 1; j++)
{
if( j >= 0 && j < 9 && map[i][j] == 'o')
{
p_temp.x = i;
p_temp.y = j;
p_temp.counts++;
ss.push(p_temp);
map[i][j] = '.';
}
}
}
}
if (ss.empty() && p_temp.counts>=2)
{
nums++;
cout << p_temp.counts << endl;
}
dfs(x, y, map);
}
if (x==9)
{
return;
}
if (map[x][y]=='o')
{
p_temp.x &
水洼问题:一个水坑附近如果存在另一个水坑则视为连接在一起,视做一个水洼,附近指的是八连通,给定一个地图,问有多少个水洼及水洼的大小
最新推荐文章于 2022-04-03 16:37:28 发布
该博客探讨了水洼问题,即在地图上,若两个水坑通过八连通方式相邻则视为一个水洼。主要内容涉及如何确定地图上的水洼数量及其大小。
摘要由CSDN通过智能技术生成