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

1A留念,贴个垃圾深搜代码

Posted by jordandandan at 2013-08-24 09:35:52 on Problem 1979
#include <iostream>
#include <memory.h>
using namespace std;
int w,h;
int map[22][22];
int ans;
int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
void dfs(int x,int y)
{
    if(x<=h&&x>0&&y<=w&&y>0)
      if(map[x][y]==0)
        {
            map[x][y] = 1;
            ans++;
            for(int i=0;i<4;i++)
              dfs(x+dir[i][0],y+dir[i][1]);
        }
    return ;
}
int main()
{
    while(cin>>w>>h)
    {
        if(w==0&&h==0)
         break;
        int x,y;
        char temp;
        for(int i=1;i<=h;i++)
          for(int j=1;j<=w;j++)
            {
                cin>>temp;
                if(temp=='.')
                  map[i][j] = 0;
                else if(temp=='#')
                  map[i][j] = 1;
                else if(temp=='@')
                  {
                      map[i][j] = 0;
                      x = i;
                      y = j;
                  }
            }
          ans = 0;
          dfs(x,y);
          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