| ||||||||||
| 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<cstring>
#include<iostream>
using namespace std;
//char input[30][30];
int room[30][30];//1为黑,0为红或边界
int canreach[30][30];//1为已经到达,0为没有到达
int tiles=0;
void dfs(int x,int y)
{
if (room[x+1][y]&&!canreach[x+1][y]){
tiles++;
//printf("Found %d %d!\n",x+1,y);
canreach[x+1][y]=1;
dfs(x+1,y);
}
if (room[x-1][y]&&!canreach[x-1][y]){
tiles++;
//printf("Found %d %d!\n",x-1,y);
canreach[x-1][y]=1;
dfs(x-1,y);
}
if (room[x][y+1]&&!canreach[x][y+1]){
tiles++;
//printf("Found %d %d!\n",x,y+1);
canreach[x][y+1]=1;
dfs(x,y+1);
}
if (room[x][y-1]&&!canreach[x][y-1]){
tiles++;
//printf("Found %d %d!\n",x,y-1);
canreach[x][y-1]=1;
dfs(x,y-1);
}
}
main()
{
int largex,largey;
int cntx,cnty;
int peoplex,peopley;
char in;
cin>>largex>>largey;
while (largex&&largey){
memset(room,0,sizeof(room));
memset(canreach,0,sizeof(canreach));
tiles=0;
for (cnty=1;cnty<=largey;cnty++){
for (cntx=1;cntx<=largex;cntx++){
cin>>in;
switch (in){
case '@':peoplex=cntx;peopley=cnty;
case '.':room[cntx][cnty]=1;break;
}
}
}
dfs(peoplex,peopley);
cout<<tiles<<endl;
cin>>largex>>largey;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator