传送门:

poj:http://poj.org/problem?id=1979

zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1165

题目大意:

给你初始坐标,标记为'#'的格子不能走,求你能走的所有格子的个数(能走的为‘.’,初始坐标用‘@’表示)

思路:

一看直接DFS就好了嘛。。。。

好几天没刷题了,回到家来水一发先~

#include<cstdio>
#include<cstring>
const int MAXN=21+2;
char map[MAXN][MAXN];
bool vis[MAXN][MAXN];
int ans;
int m,n;
void dfs(int x,int y)
{
if(vis[x][y]==true||map[x][y]=='#')
return; vis[x][y]=true;
ans++; if(x!=0)
dfs(x-1,y);
if(y!=0)
dfs(x,y-1);
if(x!=n-1)
dfs(x+1,y);
if(y!=m-1)
dfs(x,y+1); }
int main()
{ while(~scanf("%d%d",&m,&n),n||m)
{
memset(vis,0,sizeof(vis));
ans=0;
for(int i=0;i<n;i++)
scanf("%s",map[i]);
int begin_x,begin_y; for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(map[i][j]=='@')
{
begin_x=i;
begin_y=j;
} dfs(begin_x,begin_y);
printf("%d\n",ans);
}
return 0;
}

最新文章

  1. 遍历List集合,删除符合条件的元素
  2. C#导出Excel,并设置简单格式
  3. JS的十大经典算法排序
  4. ST_SRID
  5. Python快速排序
  6. windows下安装php笔记
  7. 35个jQuery小技巧(转)
  8. Eratosthenes筛选法计算质数
  9. Android入门——UI(2)
  10. 矢量切片(Vector tile)
  11. c语言中,有符号数位移
  12. CSS小技巧-怎样让每行多余的文字显示文省略号?
  13. 浅谈计算机中的IO模型
  14. Django中用户权限模块
  15. faster rcnn
  16. java算法----排序----(3)冒泡排序
  17. jenkins使用jacoco插件检测代码覆盖率(八)
  18. 并发编程之 Exchanger 源码分析
  19. stellar
  20. 冒泡排序&mdash;&mdash;Python实现

热门文章

  1. java好文章链接
  2. noi2019模拟测试赛(四十七)
  3. JNDI学习总结(3)——Tomcat下使用C3P0配置JNDI数据源
  4. Mybatis 一对多 多对1
  5. collapse折叠
  6. BZOJ1444: [Jsoi2009]有趣的游戏(Trie图,矩乘)
  7. BZOJ3510首都(LCT)
  8. Spring学习总结(5)——IOC注入方式总结
  9. 从数据库中生成XML文件
  10. [React] Call setState with null to Avoid Triggering an Update in React 16