水洼问题:一个水坑附近如果存在另一个水坑则视为连接在一起,视做一个水洼,附近指的是八连通,给定一个地图,问有多少个水洼及水洼的大小

该博客探讨了水洼问题,即在地图上,若两个水坑通过八连通方式相邻则视为一个水洼。主要内容涉及如何确定地图上的水洼数量及其大小。
摘要由CSDN通过智能技术生成
#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 &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值