ZOJ - 2412 Farm Irrigation

本文概述了AI音视频处理领域的关键技术,包括视频分割、语义识别、自动驾驶、AR增强现实、SLAM、物体检测与识别、语音识别与变声等。探讨了这些技术在实际应用中的作用与价值。
Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu

 Status

Description

Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are placed in these squares. Different square has a different type of pipe. There are 11 types of pipes, which is marked from A to K, as Figure 1 shows.


Figure 1

Benny has a map of his farm, which is an array of marks denoting the distribution of water pipes over the whole farm. For example, if he has a map

ADC
FJK
IHE
then the water pipes are distributed like

Figure 2

Several wellsprings are found in the center of some squares, so water can flow along the pipes from one square to another. If water flow crosses one square, the whole farm land in this square is irrigated and will have a good harvest in autumn.

Now Benny wants to know at least how many wellsprings should be found to have the whole farm land irrigated. Can you help him?

Note: In the above example, at least 3 wellsprings are needed, as those red points in Figure 2 show.

Input

There are several test cases! In each test case, the first line contains 2 integers M and N, then M lines follow. In each of these lines, there are N characters, in the range of 'A' to 'K', denoting the type of water pipe over the corresponding square. A negative M or N denotes the end of input, else you can assume 1 <= M, N <= 50.

Output

For each test case, output in one line the least number of wellsprings needed.

Sample Input

2 2
DK
HF

3 3
ADC
FJK
IHE

-1 -1

Sample Output

2
3


Source

Zhejiang University Local Contest 2005
 
 
 
 
分析:
图的表示+dfs。模板题。
ac代码:
//zoj2412
#include <iostream>
#include<cstdio>
using namespace std;
struct node
{
    int is;
    int left1,right1,up1,down1;
}mat[55][55];
struct node Change(char c)
{
    struct node t;
    t.down1=t.left1=t.right1=t.up1=0;
    if(c=='A')
    {
        t.left1=t.up1=1;
        return t;
    }
    if(c=='B')
    {
        t.right1=t.up1=1;
        return t;
    }
    if(c=='C')
    {
        t.left1=t.down1=1;
        return t;
    }
    if(c=='D')
    {
        t.right1=t.down1=1;
        return t;
    }
    if(c=='E')
    {
        t.up1=t.down1=1;
        return t;
    }
    if(c=='F')
    {
        t.left1=t.right1=1;
        return t;
    }
    if(c=='G')
    {
        t.left1=t.up1=t.right1=1;
        return t;
    }
    if(c=='H')
    {
        t.left1=t.up1=t.down1=1;
        return t;
    }
    if(c=='I')
    {
        t.left1=t.right1=t.down1=1;
        return t;
    }
    if(c=='J')
    {
        t.right1=t.up1=t.down1=1;
        return t;
    }
    if(c=='K')
    {
        t.left1=t.right1=t.up1=t.down1=1;
        return t;
    }
    //return t;//
}
void dfs(int x,int y)
{
    if(mat[x][y].up1&&mat[x-1][y].down1&&!mat[x-1][y].is)//!mat[x-1][y].is的判断很重要,否则出现Segmentation Fault (段错误),即堆栈耗费太大
    {
        mat[x-1][y].is=1;
        dfs(x-1,y);
    }
    if(mat[x][y].down1&&mat[x+1][y].up1&&!mat[x+1][y].is)
    {
        mat[x+1][y].is=1;
        dfs(x+1,y);
    }
    if(mat[x][y].left1&&mat[x][y-1].right1&&!mat[x][y-1].is)
    {
        mat[x][y-1].is=1;
        dfs(x,y-1);
    }
    if(mat[x][y].right1&&mat[x][y+1].left1&&!mat[x][y+1].is)
    {
        mat[x][y+1].is=1;
        dfs(x,y+1);
    }
}
int main()
{
    int i,j,m,n;
    char c;
    int count;
    while(scanf("%d%d",&m,&n)&&m>=0&&n>=0)
    {
        getchar();//读掉换行
        count=0;
        for(i=1;i<=m;i++)
        {
            for(j=1;j<=n;j++)
            {
                scanf("%c",&c);
                //printf("%c ",c);//
                mat[i][j]=Change(c);//把Change(c)的返回值赋给mat[i][j]
                mat[i][j].is=0;
                //cout<<mat[i][j].down1<<mat[i][j].left1<<" ";//通过这个找到了错误
            }
            getchar();
        }
        for(i=1;i<=m;i++)//
        {
            mat[i][1].left1=mat[i][n].right1=0;
        }
        for(i=1;i<=n;i++)//
        {
            mat[1][i].up1=mat[m][i].down1=0;
        }
        for(i=1;i<=m;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(!mat[i][j].is)
                {
                    mat[i][j].is=1;
                    dfs(i,j);
                    count++;
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
}
内容概要:本文提出了一种基于融合鱼鹰算法和柯西变异的改进麻雀优化算法(OCSSA),用于优化变分模态分解(VMD)的参数,进而结合卷积神经网络(CNN)与双向长短期记忆网络(BiLSTM)构建OCSSA-VMD-CNN-BILSTM模型,实现对轴承故障的高【轴承故障诊断】基于融合鱼鹰和柯西变异的麻雀优化算法OCSSA-VMD-CNN-BILSTM轴承诊断研究【西储大学数据】(Matlab代码实现)精度诊断。研究采用西储大学公开的轴承故障数据集进行实验验证,通过优化VMD的模态数和惩罚因子,有效提升了信号分解的准确性与稳定性,随后利用CNN提取故障特征,BiLSTM捕捉时间序列的深层依赖关系,最终实现故障类型的智能识别。该方法在提升故障诊断精度与鲁棒性方面表现出优越性能。; 适合人群:具备一定信号处理、机器学习基础,从事机械故障诊断、智能运维、工业大数据分析等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①解决传统VMD参数依赖人工经验选取的问题,实现参数自适应优化;②提升复杂工况下滚动轴承早期故障的识别准确率;③为智能制造与预测性维护提供可靠的技术支持。; 阅读建议:建议读者结合Matlab代码实现过程,深入理解OCSSA优化机制、VMD信号分解流程以及CNN-BiLSTM网络架构的设计逻辑,重点关注参数优化与故障分类的联动关系,并可通过更换数据集进一步验证模型泛化能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值