Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这代码居然是错的!!!请大家注意数组开得大一些。。。#include <stdio.h> #define N 50 char map[N][N], visited[N][N]; int m, n; int dfs(int i, int j) { if (i < 0 || i >= m || j < 0 || j >= n || visited[i][j] == 1) { return 0; } else { int ret = 1; visited[i][j] = 1; if (!(map[i][j] & 0x01)) ret += dfs(i, j-1); if (!(map[i][j] & 0x02)) ret += dfs(i-1, j); if (!(map[i][j] & 0x04)) ret += dfs(i, j+1); if (!(map[i][j] & 0x08)) ret += dfs(i+1, j); return ret; } } int main() { int i, j, cnt, max; scanf("%d%d", &m, &n); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf("%d", &map[i][j]); visited[i][j] = 0; } } cnt = 0, max = 0; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (visited[i][j] == 0) { int tmp = dfs(i, j); if (tmp > max) max = tmp; cnt++; } } } printf("%d\n%d\n", cnt, max); return 0; } 将 N 改成 60 就对了 。。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator