| ||||||||||
| 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 | |||||||||
新手~实在是找不出为啥A不了!求助!#include<iostream>
using namespace std;
int count;
int w,h;
char tiles[25][25];
int dir[2][4]={0,1,0,-1,1,0,-1,0};
int nx,ny;
void dfs(int x,int y){
count++;
tiles[x][y]='#';
for(int i=0;i<4;i++){
nx=x+dir[0][i],ny=y+dir[1][i];
if(0<=nx&&nx<w&&0<=ny&&ny<h&&tiles[nx][ny]=='.') dfs(nx,ny);
}
return;
}
void solve(){
int m,n;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(tiles[i][j]=='@') {m=i,n=j;}
}
}
dfs(m,n);
cout<<count;
}
int main() {
while(cin>>w>>h,w&&h){
count=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++)
{cin>>tiles[i][j];}
}
solve();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator