#10733. 搜索算法第二题(NOIP2013)

搜索算法第二题(NOIP2013)

第二题(NOIP2013)

#include<cstring>
#include<iostream>
using namespace std;
const int SIZE=100;
int n,m,p,a[SIZE][SIZE],cnt;

void colour(int x,int y){
    cnt++;
    a[x][y]=1;
    if((x>1)&&(a[x-1][y]==0)) colour(x-1,y);
    if((y>1)&&(a[x][y-1]==0)) colour(x,y-1);
    if((x<n)&&(a[x+1][y]==0)) colour(x+1,y);
    if((y<m)&&(a[x][y+1]==0)) colour(x,y+1);
}

int main(){
    int i,j,x,y,ans;
    memset(a,0,sizeof(a));
    cin>>n>>m>>p;
    for(i=1;i<=p;i++){
        cin>>x>>y;
        a[x][y]=1;
    }
    ans=0;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            if(a[i][j]==0){
                cnt=0;
                colour(i,j);
                if(ans<cnt) ans=cnt;
            }
    cout<<ans<<endl;
    return 0;
}
  1. 【判断题】由于没有赋初值,该程序会运行错误。
    {{ select(1) }}
  • 正确
  • 错误
  1. 【判断题】如果将第18行去掉,程序结果会发生改变。
    {{ select(2) }}
  • 正确
  • 错误
  1. 【判断题】如果将第30行的ans<cnt改成ans<=cnt,输出结果会发生改变。
    {{ select(3) }}
  • 正确
  • 错误
  1. 【判断题】该程序有可能输出114514。
    {{ select(4) }}
  • 正确
  • 错误
  1. 【选择题】若输入为:
    6 5 9
    1 4
    2 3
    2 4
    3 2
    4 1
    4 3
    4 5
    5 4
    6 4
    则输出结果是( )。
    {{ select(5) }}
  • 114514
  • 1919810
  • 7
  • 8
  1. 【选择题】该程序的时间复杂度为( )。
    {{ select(6) }}
  • O(1)
  • O(n)
  • O(n×m)
  • O(2ⁿ)