| ||||||||||
| 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 | |||||||||
输出重定向未注释,贡献四个WA#include <iostream>
#define M 20 + 10
#define N 20 + 10
using namespace std;
int m, n;
int count;
char map[M][N];
int dir[4][2] = {{-1, 0},{1, 0},{0, 1},{0, -1}};
void dfs(int x, int y)
{
int newx, newy;
map[x][y] = '#';
for(int i = 0; i < 4; i++)
{
newx = x + dir[i][0];
newy = y + dir[i][1];
if(newx >= 0 && newx < n && newy >= 0 && newy < m && map[newx][newy] == '.')
{
count ++;
dfs(newx, newy);
}
}
}
int main()
{
int x = 0, y = 0;
int result = 0;
//freopen("input.txt","r",stdin);
while(scanf("%d%d", &m, &n) != EOF && m && n)
{
memset(map, 0, sizeof(map));
count = 1;
for(int i = 0; i < n; i++)
{
scanf("%s", &map[i]);
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
if(map[i][j]== '@'){
x = i;
y = j;
map[x][y] = '.';
}
}
}
dfs(x, y);
result = count;
cout <<result<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator