【搜索中的Floodfill模型】

这篇博客介绍了Floodfill模型在ACW1097池塘计数、ACW1098城堡问题和ACW1106山峰和山谷三个问题中的应用。通过Floodfill解决连通性问题,包括判断格子间的连通状态和确定最大房间数量。博客提供了对应的解题思路和代码实现。
摘要由CSDN通过智能技术生成

1.ACW1097:池塘计数
题意:‘W’:水、’.’:干的,求水坑数。
思路:最基本的Floodfill。
代码如下:

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 1010;
typedef long long LL;
typedef pair<LL, LL> PII;
char c[N][N];
LL n,m;
bool st[N][N];
int dx[8] = {
   -1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {
   -1, 0, 1, 1, 1, 0, -1, -1};
void bfs(LL sta,LL ed)
{
   
    queue<PII>q;q.push({
   sta,ed});st[sta][ed]=true;
    while(q.size())
    {
   
        PII t=q.front();q.pop();
        for(int i=0;i<8;i++)
        {
   
            LL ix=t.x+dx[i],iy=t.y+dy[i];
            if(ix<=0||iy<=0||ix>n||iy>m||st[ix][iy]||c[ix][iy]=='.') continue;
            q.push({
   ix,iy})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值