第二题(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;
}
- 【判断题】由于没有赋初值,该程序会运行错误。
{{ select(1) }}
- 【判断题】如果将第18行去掉,程序结果会发生改变。
{{ select(2) }}
- 【判断题】如果将第30行的
ans<cnt改成ans<=cnt,输出结果会发生改变。
{{ select(3) }}
- 【判断题】该程序有可能输出114514。
{{ select(4) }}
- 【选择题】若输入为:
6 5 9
1 4
2 3
2 4
3 2
4 1
4 3
4 5
5 4
6 4
则输出结果是( )。
{{ select(5) }}
- 【选择题】该程序的时间复杂度为( )。
{{ select(6) }}