传送门:

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;
}

POJ 1979 Red and Black (zoj 2165) DFS的更多相关文章

  1. POJ 1979 Red and Black (红与黑)

    POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a ...

  2. POJ 1979 Red and Black dfs 难度:0

    http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...

  3. poj 1979 Red and Black(dfs)

    题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...

  4. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  5. POJ 1979 Red and Black【DFS】

    标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include< ...

  6. POJ 1979 Red and Black (DFS)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  7. POJ 1979 Red and Black (简单dfs)

    题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...

  8. poj 1979 Red and Black 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...

  9. OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑

    1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...

随机推荐

  1. ssm框架的总结

    ssm对应的是spring+springmvc+mybatis, 一.spring,略. 二.spring mvc是spring提供的mvc模块, 从图中可以看出,springmvc的模块划分非常多, ...

  2. ssm 框架学习-1

    理论理解 +项目阅读 SpringSpring就像是整个项目中装配bean的大工厂,在配置文件中可以指定使用特定的参数去调用实体类的构造方法来实例化对象.Spring的核心思想是IoC(控制反转),即 ...

  3. git把本地文件上传到github上的步骤

    1.清除clean 2.返回上一级cd .. 3.克隆仓库地址git clone+地址 4.添加忽悠文件vim .gitignore 5查看cat .gitignore 6.进入到test,并且添加所 ...

  4. Windows学习总结(3)——成为电脑高手必备的cmd命令大全

    曾经看电影和电视里面电脑黑客快速敲击电脑键盘,一行行命令在电脑屏幕闪过,一个回车过后,一排排英文象走马灯一样在屏幕上转瞬即逝,那才是我们梦寐以求的高手,有木有!实际上,不光是黑客和系统维护人员,一般的 ...

  5. libssh2进行远程运行LINUX命令

    /** * CSSHClient.h * @file 说明信息.. * DATE February 13 2015 * * @author Ming_zhang */ #ifndef _CSSHCLI ...

  6. Python笔记---错误笔记

    Python---错误笔记 1. Python编码问题: 我们在编写 Python 脚本时,往往会写上中文凝视. 可是有时候,当我们执行程序时.却发现例如以下错误:SyntaxError: Non-A ...

  7. 23. Node.Js Buffer类(缓冲区)-(三)文件读取实例

    转自:https://blog.csdn.net/u011127019/article/details/52513109

  8. react radio onchange事件点击无效

    记: 项目需求:   页面中radio默认选中        第一次进去页面   点击radio的时候不管怎样点击    都是选中 连onChange事件都没触发 进入页面  点击刷新   点击rad ...

  9. 洛谷P3403跳楼机(最短路构造/同余最短路)

    题目-> 解题思路: 最短路构造很神啊. 先用前两个值跑在第三个值模意义下的同余最短路(这步贪心可以证明,如果第三步长为z,那么如果n+z可以达到,n+2z同样可以达到) 最后计算与楼顶差多少个 ...

  10. iOS多语言(国际化)开发(尾随系统 + APP内手动设置)

    一:尾随系统切换语言 1>创建好项目project后, 新建一个多语言文件: 2>加入要设置的语言类型: 3>加入成功 细心的朋友可能会发如今English后面写的是3 Files ...