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

乃格兰!数组开30就WA了,开50就AC,题目不是说1-20么!

Posted by hustcswgy at 2011-08-06 12:20:21 on Problem 1111
#include<stdio.h>
#define MAXN 50 /* 开30竟然WA!!! */

int main()
{
    int n, m, x, y;
    while(scanf("%d%d%d%d", &n, &m, &x, &y), n)
    {
        int i, j;
        char map[MAXN][MAXN];
        int si[MAXN*MAXN], sj[MAXN*MAXN]; int sp = -1;
        int sum;
        for(i = 0; i <= n+1; i ++) for(j = 0; j <= m+1; j ++) map[i][j] = '.';
        for(i = 1; i <= n; i ++)
            scanf("%s", map[i]+1);
        if(map[x][y] == 'X')
        {
            sp++; si[sp] = x; sj[sp] = y;
            while(sp >= 0) /* DFS */
            {
                int ti = si[sp], tj = sj[sp]; sp--;
                if(map[ti][tj] == 'X')
                {
                    map[ti][tj] = 'A';
                    sp++; si[sp] = ti-1; sj[sp] = tj-1;
                    sp++; si[sp] = ti-1; sj[sp] = tj;
                    sp++; si[sp] = ti-1; sj[sp] = tj+1;
                    sp++; si[sp] = ti; sj[sp] = tj-1;
                    sp++; si[sp] = ti; sj[sp] = tj+1;
                    sp++; si[sp] = ti+1; sj[sp] = tj-1;
                    sp++; si[sp] = ti+1; sj[sp] = tj;
                    sp++; si[sp] = ti+1; sj[sp] = tj+1;
                }
            }
        }
        sum = 0;
        for(i = 1; i <= n; i ++)
            for(j = 1; j <= m; j ++)
                if(map[i][j] == 'A')
                {
                    if(map[i-1][j] != 'A') sum++;
                    if(map[i][j-1] != 'A') sum++;
                    if(map[i][j+1] != 'A') sum++;
                    if(map[i+1][j] != 'A') sum++;
                }
        printf("%d\n", sum);
    }
    return 0;
}

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