Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这代码居然是错的!!!请大家注意数组开得大一些。。。

Posted by bestofme at 2014-04-18 21:13:06 on Problem 1164
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator