AI题库 · 信息学奥赛-提高级题库
题目分享 #22653
#include<iostream>
#include<string >
using namespace std;
const int SIZE = 100;
int n, m, p, a[SIZE] [SIZE], count;
void colour (int x, int y)
{
Count++;
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)
{count = 0;
colour (i , j);
if (ans <count)
ans <count;
}
count<<ans<<endl;
return 0;
}输入:
6 5 9
1 4
2 3
2 4
3 2
4 1
4 3
4 5
5 4
6 4
输出:_________
AI题库 · 编程考级与信奥赛真题库
查看答案 →
复制链接后可在微信、QQ、小红书等平台粘贴分享;答案与解析在题目页。