| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
优雅飘逸的代码~//============================================================================
//
// File : poj1979.cpp
// Author : flowertree
// Time : 2015年9月25日
// About : DFS
//
//============================================================================
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAX 25
char s[MAX][MAX];
int sum;
int a[4][2] = {-1,0,1,0,0,1,0,-1};
void DFS(int i,int j,int m,int n)
{
s[i][j] = '#';
sum++;
int tempx,tempy;
for(int k = 0; k < 4; k++)
{
tempx = i + a[k][0];
tempy = j + a[k][1];
if((tempx >= 0 && tempx < m) && (tempy >= 0 && tempy < n) && s[tempx][tempy] == '.')
{
DFS(tempx,tempy,m,n);
}
}
}
int main()
{
int m,n;
int markx,marky;
while(cin >> n >> m,m && n)
{
for(int i = 0; i < m; i++)
{
scanf("%s",s[i]);
for(int j = 0; j < n; j++)
{
if(s[i][j] == '@')
{
markx = i;
marky = j;
}
}
}
sum = 0;
DFS(markx,marky,m,n);
cout << sum << endl;
}
system("pause");
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator