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

真简单,递归FooldFill一次就AC

Posted by 1428 at 2008-04-18 21:34:39 on Problem 1979
#include <iostream>

using namespace std;

long m,n,i,j,total;
char a[101][101];
long b[101][101];

void search (long x,long y)
{
     total++;
     b[x][y]=1;
     if (x-1>=0) {
                 if ((a[x-1][y]=='.')&&(b[x-1][y]==0)) search (x-1,y);
                 }
     if (x+1<m) {
                if ((a[x+1][y]=='.')&&(b[x+1][y]==0)) search (x+1,y);
                }
     if (y-1>=0) {
                 if ((a[x][y-1]=='.')&&(b[x][y-1]==0)) search (x,y-1);
                 }
     if (y+1<n) {
                if ((a[x][y+1]=='.')&&(b[x][y+1]==0)) search (x,y+1);
                }
}

int main ()
{
    while (1)
          {
          cin>>n>>m;
          if ((n==0)&&(m==0)) break;
          for (i=0;i<m;i++)
              for (j=0;j<n;j++)
                  b[i][j]=0;
          for (i=0;i<m;i++)
              cin>>a[i];
          for (i=0;i<m;i++)
              for (j=0;j<n;j++)
                  if (a[i][j]=='@') {
                                    total=0;
                                    b[i][j]=1;
                                    search (i,j);
                                    }
          cout<<total<<endl;
          }
    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