POJ 1979 Red and Black (zoj 2165) DFS
传送门:
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的更多相关文章
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- POJ 1979 Red and Black dfs 难度:0
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...
- poj 1979 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ 1979 Red and Black【DFS】
标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include< ...
- POJ 1979 Red and Black (DFS)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ 1979 Red and Black (简单dfs)
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...
- poj 1979 Red and Black 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...
随机推荐
- 动态引入js代码
var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = & ...
- Codefroces B. New Skateboard
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 2017国家集训队作业[agc014d]Black and White Tree
2017国家集训队作业[agc014d]Black and White Tree 题意: 有一颗n个点的树,刚开始每个点都没有颜色.Alice和Bob会轮流对这棵树的一个点涂色,Alice涂白,B ...
- 使用Cygwin在Windows上体验Linux的快感
前言 记得大学的时候就以前使用过Cygwin,可惜当时没有发现她的美,我相信如今大多数朋友可能会更加倾向于使用Git或者干脆直接使用虚拟机以及原生Unix. 只是对于刚进入Linux的世界新人来说,使 ...
- HDU 1495 很可乐(BFS 倒水问题)
题意 将体积为s的可乐 利用容积分别为n和m的两个杯子平均分为两份 至少须要倒多少次可乐 能够把容器s,n,m中装的可乐量看成一种状态 容器都是没有刻度的 所以每次倒可乐要么把自己倒完 要么把 ...
- UVA 11346 Probability (几何概型, 积分)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=2321">https://uva ...
- postgresql 查看单个表大小
3中方法,不论什么一个都行 方法一 ,查一个表 select pg_size_pretty(pg_relation_size('table_name')); 方法二 ,查出全部表并按大小排序 SELE ...
- 78.pipe多管道云端,客户端通信
压力测试截图: 云端 定义管道缓存区大小,最多连接数量(线程个数),当前线程个数,管道名字 //缓冲区大小 #define SIZE 4096 //最多连接数量 #define MAX_CONNECT ...
- 前端项目中常用es6知识总结 -- Async、Await让异步美如画
项目开发中一些常用的es6知识,主要是为以后分享小程序开发.node+koa项目开发以及vueSSR(vue服务端渲染)做个前置铺垫. 项目开发常用es6介绍 1.块级作用域 let const 2. ...
- Linux登录状态
1.hostname 显示主机名称.设置主机名称 1)显示主机名称 xiaohuang@xiaohuang-virtual-machine:~$ hostname xiaohuang-virtual- ...