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

想多了,随便一码居然就AC了……

Posted by xijunlee93 at 2013-04-22 18:42:21 on Problem 1979
#include<iostream>
using namespace std;
int Imap[21][21],ans,w,h,si,sj;
int diri[4]={-1,0,1,0};
int dirj[4]={0,1,0,-1};

char Cmap[21][21];
void search(int ii,int jj)
{
     if (ii<h&&ii>=0&&jj>=0&&jj<w)
      if (Cmap[ii][jj]=='.'&&Imap[ii][jj]==0)
      {
       Imap[ii][jj]=1;
       ans++;
       int i;
       for (i=0;i<4;i++)
       search(ii+diri[i],jj+dirj[i]);
      }
     return;
}

int main()
{
    int i,j,k;
    while(cin>>w>>h&&w!=0)
    {
        memset(Imap,-1,sizeof(Imap));
        memset(Cmap,0,sizeof(Cmap));
        ans=1;
        for (i=0;i<h;i++)
        cin>>Cmap[i];
        for (i=0;i<h;i++)
         for (j=0;j<w;j++)
         {
          if (Cmap[i][j]=='@')
          {si=i;sj=j;}
          if (Cmap[i][j]=='.')
          Imap[i][j]=0;
         }
        for (k=0;k<4;k++)
        search(si+diri[k],sj+dirj[k]);
        cout<<ans<<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