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

i 没在函数内部定义引发的血案!!!!

Posted by lyz963254 at 2014-08-19 22:16:11 on Problem 1562
#include <iostream>
#include <cstdio>

using namespace std;

const int M = 1005;

int i,j;
int m,n;

char map [101][101];
int dir[8][2] = { {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1} };

void DFS(int x,int y)
{
    int xx,yy;
    int i;
    map[x][y] = '*' ;//保证不再遍历这个方格。
    for(i=0;i<8;i++)
    {
        xx = x + dir[i][0];
        yy = y + dir[i][1];
        if (xx<0||yy<0||xx>=m||yy>=n) continue ;
        if (map[xx][yy] == '@' )
        DFS(xx,yy);

    }

}

int main ()
{

   int ans;
   while (scanf("%d%d",&m,&n)&&m!=0)
   {


       for (i=0;i<m;i++)
       scanf("%s",map[i]);

       ans = 0;

       for (i=0;i<m;i++)
       {
           for (j=0;j<n;j++)
           {
               if (map[i][j] == '@')
               {
                   DFS(i,j) ;
                   ans ++;
               }
           }
       }

       printf("%d\n",ans );

   }

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