比赛 20121016 评测结果 WWWWAWAWAA
题目名称 家族 最终得分 40
用户昵称 王者自由 运行时间 0.009 s
代码语言 C++ 内存使用 2.04 MiB
提交时间 2012-10-16 20:21:47
显示代码纯文本
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. const int N = 200 + 10;
  6. const int X[] = {0, 0, -1, 1};
  7. const int Y[] = {-1, 1, 0, 0};
  8. int n, m, s;
  9. char c[N][N];
  10. bool v[N][N];
  11. void DFS(int x, int y) {
  12. if(x < 0 || y < 0 || x >= n || y >= m) return;
  13. if(v[x][y] || !('a' <= c[x][y] && c[x][y] <= 'z')) return;
  14. v[x][y] = 1;
  15. for(int k=0; k<4; k++)
  16. DFS(x + X[k], y + Y[k]);
  17. }
  18. int main() {
  19. freopen("family.in", "r", stdin);
  20. freopen("family.out", "w", stdout);
  21. scanf("%d", &n);
  22. for(int i=0; i<n; i++) {
  23. gets(c[i]);
  24. m = max(m, (int) strlen(c[i]));
  25. }
  26. for(int i=0; i<n; i++)
  27. for(int j=0; j<m; j++)
  28. if('a' <= c[i][j] && c[i][j] <= 'z')
  29. if(!v[i][j]) { s++; DFS(i, j); }
  30. printf("%d\n", s);
  31. return 0;
  32. }