| ||||||||||
| 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 | |||||||||
好久没做到这么爽的题目了,写了10分钟就AC了,附代码Source Code
Problem: 1111 User: yzhw
Memory: 456K Time: 0MS
Language: G++ Result: Accepted
Source Code
# include <iostream>
using namespace std;
char map[22][22];
bool scan[22][22];
int det(int x,int y)
{
if(map[x][y]=='.'||scan[x][y]) return 0;
else
{
int res=0;
scan[x][y]=1;
if(map[x-1][y]=='.')
{
res++;
}
if(map[x+1][y]=='.')
{
res++;
}
if(map[x][y-1]=='.')
{
res++;
}
if(map[x][y+1]=='.')
{
res++;
}
res+=det(x+1,y)+det(x-1,y)+det(x,y+1)+det(x,y-1);
res+=det(x+1,y-1)+det(x+1,y+1)+det(x-1,y+1)+det(x-1,y-1);
return res;
}
}
int main()
{
while(1)
{
memset(map,'.',sizeof(map));
memset(scan,0,sizeof(scan));
int r,c,x,y;
cin>>r>>c>>x>>y;
if(!r&&!c&&!x&&!y) break;
for(int i=1;i<=r;i++)
for(int j=1;j<=c;j++)
cin>>map[i][j];
cout<<det(x,y)<<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