poj 3620

简介: 题意:给出一个矩阵,其中有些格子干燥、有些潮湿。       如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大       的湖泊,求最大的湖泊。       也就是求出最大的连在一块儿的潮湿的格子的数目。

题意:给出一个矩阵,其中有些格子干燥、有些潮湿。

      如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大

      的湖泊,求最大的湖泊。

      也就是求出最大的连在一块儿的潮湿的格子的数目。

 

#include<iostream>
#include<cstring>
using namespace std;
int aa[105][105]={0};
int dir[4][2]={-1,0,1,0,0,-1,0,1};
int sum=0,ans=0,n,m,k;
void dfs(int a,int b)
{
    int a1,b1;
    ans++;
    aa[a][b]=0;                 
    for(int i=0;i<4;i++)
    {
        a1=a+dir[i][0];
        b1=b+dir[i][1];
        if(a1>=1&&a1<=n&&b1>=1&&b1<=m&&aa[a1][b1])
            dfs(a1,b1);
            //不用回溯的原因,因为只要是能连续到达的店连成湖的肯定都能连一块的;
            
    }
}
int main()
{
    cin>>n>>m>>k;
    for(int i=0;i<k;i++)
    {int x,y;
        cin>>x>>y;

        aa[x][y]=1;

    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {   if(aa[i][j])
    {   ans=0;
        dfs(i,j);
        if(ans>sum)sum=ans;
    }
    }
    cout<<sum<<endl;


    return 0;
}

 

相关文章
|
3月前
|
算法 数据建模
Poj 3169(差分约束系统)
Poj 3169(差分约束系统)
20 0
|
C语言
poj 2503 查字典
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language.
838 0
poj 3664
http://poj.org/problem?id=3664 进行两轮选举,第一轮选前n进入第二轮,第二轮选最高   #include #include using namespace std; struct vote { int a,b; int c; ...
705 0
poj 1455
Description n participants of > sit around the table. Each minute one pair of neighbors can change their places.
599 0
poj-1006-Biorhythms
Description 人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易高度集中。
587 0
|
算法 数据建模 机器学习/深度学习
poj1273Drainage Ditches
1 #include 2 /* 3 题意:就是寻找从源点到汇点的最大流! 4 要注意的是每两个点的流量可能有多个,也就是说有重边,所以要把两个点的所有的流量都加起来 5 就是这两个点之间的流量了! 6 ...
827 0
|
存储
大数加法-poj-1503
poj-1503-Integer Inquiry Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking vari
1100 0