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 haha___wokao at 2013-11-01 21:00:22 on Problem 1979
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
bool flag[55][55];
int width,length,num=0;
char s[55][55];
void dfs(int i,int j)
{
    flag[i][j]=true;
    if(i+1<width&&s[i+1][j]=='.'&&flag[i+1][j]==false)
    dfs(i+1,j);
    if(i-1>=0&&s[i-1][j]=='.'&&flag[i-1][j]==false)
    dfs(i-1,j);
    if(j+1<length&&s[i][j+1]=='.'&&flag[i][j+1]==false)
    dfs(i,j+1);
    if(j-1>=0&&s[i][j-1]=='.'&&flag[i][j-1]==false)
    dfs(i,j-1);
}
int main()
{
    int n=0,m=0;
    while((cin>>length>>width)&&width){
    num=0;
    memset(flag,false,sizeof(flag));
    for(int i=0;i<width;i++)
      for(int j=0;j<length;j++)
         {
             cin>>s[i][j];
             if(s[i][j]=='@')
              {
                  n=i;
                  m=j;
              }
         }
    dfs(n,m);
    for(int i=0;i<width;i++)
      for(int j=0;j<length;j++)
       {
           if(flag[i][j])
            num++;
       }
    cout<<num<<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