经典指数          
原因
1526
浏览数
0
收藏数
 

#include #include #define SIZE 100 int n, m, p, count; int a[SIZE][SIZE]; 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));     scanf("%d%d%d", &n, &m, &p);     for (i = 1; i <= p; i++) {         scanf("%d%d", &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;             }     printf("%d\n", ans);     return 0; } 输入: 6 5 9 1 4 2 3 2 4 3 2 4 1 4 3 4 5 5 4 6 4 输出:_____1____

     举报   纠错  
 
切换
暂时还没有答案,欢迎分享你的解答 . . .
撰写答案
扫描后移动端查看本题