回复 10楼 azzbcc
对对对,一个,就是连起来就算一个,我觉得我那个是对的,但是输出不了
#include<stdio.h> #define MAX 10 int a[MAX][MAX]; int m, n; void Init() { int i, j; for (i = 0;i <= m+1;++i) a[i][0] = a[i][n+1] = -1; for (i = 0;i <= n+1;++i) a[0][i] = a[m+1][i] = -1; for (i = 1;i <= m;++i) for (j = 1;j <= n;++j) scanf("%d", &a[i][j]); } int Judge(int x, int y) { if (-1 == a[x][y]) return -1; if (0 == a[x][y]) return 0; a[x][y] = 0; Judge(x, y - 1);//左 Judge(x - 1, y);//上 Judge(x, y + 1);//右 Judge(x + 1, y);//下 return 1; } int Get() { int number = 0; for (int i = 1;i <= m;++i) for (int j = 1;j <= n;++j) if (Judge(i, j)) ++number; return number; } int main() { int N; scanf("%d", &N); while (N--) { scanf("%d%d", &m, &n); Init(); printf("%d\n", Get()); } return 0; }